I have a Google Spreadsheet containing a number of sheets, each or which I have protected using the "Except certain cells' routine in order to protect shared users from editing areas they shouldn't.
I also have a function to insert rows but this obviously fails when running as a shared user due to the protection.
The Insert Rows function works 100% with no protection added.
How can I temporarily change the active user to 'me' while the script is running and then 'remove me' when completed leaving the sheet in its original state including all the protection?
The most viable option is to have a web App to insert the row where desired. You can pass the sheet Name and row No via a get or post method. The below method uses a get method. Your google script would look something like this:
Next, you will deploy a web App which will process the get request and add new rows to the sheet. The code would look like this:
Make sure to run the webApp once to give it authorization/permission to edit your google sheets. Since the webApp will run under your authorization, it would be able to insert Row without an issue of permission. Also, you can add a unique ID(Email ID of the effective User?) to the get request to make sure only valid request from within the google sheets scripts is processed.
If you would like more details on the web app you can find it here: https://developers.google.com/apps-script/guides/web