Sharing google sheet with restrictions - google-apps-script

I've built my google sheet, and shared it with the team, the sheet has an entry point, where the user is entering some data, and balance data of the sheet is changing dynamically based on this input.
If 2 persons are using the sheet at the same time, the data will be changed based on the last guy who use this entry field, and the data the other guy seeing will be changed accordingly.
my sheet is here
The sheet is locked except the yellow shaded cell, which is allowed to be changed by the user.
Is there a way to allow each user to see the data based on his input parameter, without getting it destroyed when used by others!

I don't think what you're looking for is possible as Sheets is designed to be used for collaboration and edits will always be shown in real time. Consider adding multiple sheets and assign them to each of your team members with the exact formatting and formulas as the original so they can access and input their data independently.

Related

How do you tell if a Google Sheet has script attached or not?

Is it possible to know, programmatically, whether a Google Sheets document has a script object attached?
After finding that out, I'm also interesting in knowing what properties can be discovered about the attached script and whether permissions for it can be discovered and defined?
The Sheets API on developerMetadata looks like a place one might start.
Unfortunately what you want cannot be achieved as there is no way to check if a spreadsheet has a script attached to it.
The only way to check if a spreadsheet and a script are bound together is the other way around: by checking from a script if there is any spreadsheet attached to it.
This can be done by using the getActiveSpreadsheet() method.
As for the developerMetadata, according to the documentation, this simply refers to the data from the spreadsheet itself associated with the developer metadata and has nothing to do with any scripts bound to it.
Developer metadata may be used to associate arbitrary data with various parts of a spreadsheet and will remain associated at those locations as they move around and the spreadsheet is edited. For example, if developer metadata is associated with row 5 and another row is then subsequently inserted above row 5, that original metadata will still be associated with the row it was first associated with (what is now row 6). If the associated object is deleted its metadata is deleted too.
It is also important to note that the script bound to the spreadsheet is not an object, therefore you cannot retrieve it.
What you can do in this situation however, is to file a feature request for the Sheets API following the link here and don't forget to include all the details that might be needed for this.

Why do two users sometimes see different values from importrange?

I have a very strange problem, the description can be a bit chaotic.
I have two spreadsheets A and B. One sheet inside A is importing data with importrange from the B. The problem is that sometimes two user see different values in that sheet.
Details:
I have two scripts inside A:
one that copies the values from the imported range to another sheet
one that calls that WebApp that changes data in B.
When two users have the A open and one of them makes changes to the B via script and then uses the other script which copies the values, everything is fine. But if one user closes the A, the other makes changes in the B with the script and when the first user reopens the spreadsheet, he will see new values, but if he uses the values copying script, the range containing the values from importrange will show old values. Oddly enough, the script that copies values from that range will copy the new correct values even if we don't see them.
The problem goes away when I manually make some changes to spreadsheet B. I don't know, it's like spreadsheet B doesn't refresh when I make changes via script or something
Do you have any ideas what is the reason for this and maybe how to solve it. I think that I can get round this problem but I would not.
Two Google Sheets users might see diffent values on the same spreasheet because formula calculation (including those that make API calls like IMPORTRANGE) are triggered by user actions like opening or edited the spreadsheet.
Some function also might recalculated by changes made by scripts so it's actually possible that an script could "see" different values than those that are seeing by the users.
If you need that the users see the same values, should consider to periodically "freeze" them i.e. make a copy of the spreadsheet then replace the formulas by their results.
Another option is to share the screen rather than relaing on the "real time" collaboration feature of Google Sheets.

Is it possible for a GAS script to lock a Google Sheet so nobody else can alter it until the script is done

I am familiar with the Lock Service but that is only for locking scripts.
I have some code that will "process" a large Google Sheet. My script needs to re-order the rows. I need/want to make it so while the script is running nobody else can change the order. However, I still need another script to be able to append rows.
We use a Google Form for our team's intake. It appends rows to a sheet. I have an hourly job that will go through all the rows/records and "process them". I have a column that stores the last time a record/row was "processed". I want to sort on that column such that the "oldest" records are on top and then start processing from the top down. If the script fails or times out then the next iteration will just start over...
I know I could use getValues or getDisplayValues to get an array and then write the array back but I worry what would happen if someone sorted the rows as it would muck things up when writing the array back.
Is there some way to accomplish my goal? I want to be able to process the records, and maintain row order to avoid breaking my processing.
The way to block a spreadsheet "completely" is by changing the spreadsheet sharing settings. Remove all editors or change them to viewers, once your script finish, change them back as editors. In a extreme case, usa a second account to act as the owner of the critical files / spreadsheets and only use it for this purpose,so you could block your regular account for doing changes to the spreadsheet.
NOTE: A Google Form editResponseUrl could be used to edit the linked spreadsheet.
I'm facing a similar situation but I took a different approach, I'm using an index/key column (you could use the timestamp column) and using the index/key to save each edited row to the right position, then write the whole resulting array in a single operation (by using setValues()). In my case this is simple because I only require values, I'm not worried about notes, data validation, conditional formatting, comments, etc. and there isn't a Google Form linked to my spreadsheet.
Related
Google Spreadsheet -- get sharing permissions by script
Any way to share google docs programmatically?

How to program a column in Google sheets to be grayed out from user input depending on the Google account viewing the document

I would like to gray out a column (e.g., column H) based on who opened this document - as in based on the Google account that is viewing or editing this google sheet.
As you could see in the below picture, I want column H grayed out (not hidden but disabled for user input) when anyone else other than a specific person is viewing/editing it.
Take a look at protecting ranges, it will provide with just what you need to avoid users from editing a particular range of the sheet. In short, it work similar to file permissions, you can assign edit permissions in particular ranges so that only you (assuming you're the file owner) can edit in that range.
As for the coloring, I would advise against this, it could be achieved with a script, but if two users have the Sheet open at the same time (one with permissions, one without) one of them will see the column in a way they shouldn't. If you set the protected ranges, they will see a window telling them they cannot edit that cell.

How to hide certain columns for a user?

On a shared Google spreadsheet:
I don't want a specific user in my domain to view columns with sensitive data, but this person should still be able to edit the rest of the spreadsheet.
I tried creating a 'master' spreadsheet and using importrange to bring the data into a 'shared' sheet, but once I edit any cell in the shared spreadsheet, importrange no longer works as the sheet is emptied out.
Is there a quick way to do this, maybe using scripting?
After some research and trying various different options, I was finally able to achieve what I want using the importrange function.
At first, I tried using a combination of hide columns & protect range, but this wouldn't work because a simple copy & paste would reveal the contents of the hidden columns.
Solution: The 'master' spreadsheet does not have any sensitive column data and can be shared with everyone in the organization... I then ADD the sensitive data to a new spreadsheet and use importrange to grab contents from the 'master'. (Previously I had the roles reversed, but this didn't work)
You may want to add unique keys per row entry so that sorting etc won't mess things up when you zip-up the sensitive data and the 'master' data.
I came here looking for a way to share only certain columns of a spreadsheet with a customer, but not all.
As noted in the other answer, using =IMPORTRANGE works well, but a clever customer could simply edit the function and see the other columns.
My solution was to first create a 'proxy' spreadsheet that imported only the columns I want the customer to see. This proxy spreadsheet is not shared.
Then, I created another spreadsheet that imported the columns from the proxy, and shared that spreadsheet with the customer. This way, even with edit privileges, it's impossible for him to see anything that isn't on the proxy spreadsheet.
A bit clunky to be sure, but it worked perfectly for my situation.