I have created a script on google sheets App script that will take a form submission, and put it into a new sheet. The way it does this is by calling on the last row with data, but when two forms are submitted at the same time, only one is submitted as the first did not have enough time to go through. Is there a way to still keep google forms open and delay the responses from updating the spreadsheet by 5 or so second intervals? I don't want data to be missed if two forms submit at the same time. Any help is appreciated as I am a COMPLETE beginner.
Casey, I think what you need is LockService. You can set the lock prior to any edits and release it once you've updated the sheet. If any concurrent updates need to happen, they will wait until the lock is released. Full example here.
Related
I developed numbers of custom scripts in a project which supposed to run over lastrow of data in response sheet linked to a gform upon submission of that gform. When tested, it took around 45 seconds to finish all the custom scripts.
Now here is where I get worried and I'm looking for a firm answer which I still cannot find from google search. Within that 45 seconds of processing, other gform users can submit the form and I'm thinking every latest submission will be taken as lastrow of data in the response sheet.
So, since my custom scripts will always refer and/or getValue(s) on the lastrow of response sheet, will that makes some of my scripts will jump on to the latest row of data before it finishes the previous one just because the latest submission is before the 45 seconds is finished? I'm so worried that if it is yes, that definitely will make the output become a disaster.
Add Info. I have one main function that calls other subfunctions chronologically and some subsubfunction(s) been called from that subfunction. Please refer below:-
function MAINFUNCTION(){
var sheet=SpreadsheetApp.getActiveSheet();
MYfunctionA();
MYfunctionB();
MYfunctionC();
}
MYfunctionB(){
//something done here..
mysubfunctionB();
return
}
MYfunctionA(){
//something done here..
return
}
MYfunctionC(){
//something done here..
return
}
So, if LockService is the solution, must it be applied to every subfunction? Another thing, what will happen if there's a google service/server error during that locktime? will it release the lock and proceed with the next record?
Or will it auto-retry? Because during testing, sometimes I got this service/server error prompted and usually I just rerun it back, but I wonder what will happen if this project is launched and used by many users almost concurrently?
I've currently got a trigger on form submit to run my code which pulls in the submitted data and emails a summary to the user. I need to perform calculations on the submitted data and provide those results in the summary email. I've been able to hard code this and I have a working script but I want to do the calculations on one of the sheets instead. I've got another sheet setup to pull in the form data and perform the calculations but it seems the problem is that when the form data is submitted, none of the other sheets are updated so if I try to pull calculations from the other sheets it will not include the latest entry.
I've tried getting data from other sheets but I don't think the other sheet calculations are refreshing to include the newly submitted data, or the code is executing before the sheets can refresh, possibly order of operations limitation. The desired goal would be to have a user submit the form, then have all sheets using that data pull it in and complete calculations, then send an email using the newly calculated results. Ideally pulling data from multiple sheets.
I'm thinking the "on form submit" trigger is not appropriate here, instead maybe I need to have an event occur on the sheet or sheets I'm using to calculate that triggers an email. Or does anyone know if there's a way to force all sheets to update and fields to calculate before continuing to execute the code?
Any ideas? Thanks!
I'm not sure if I got 100% what you're looking for but you need to know that if it's your function who is opening a Spreadsheet and writing data on it, you can't add any trigger.
Trigger can only run following a "human" action (onOpen, onEdit..)
Pl. try importrange in the target sheet/sheets to pull data from the form sheet.
You have to maintain "completed" in a seperate sheet.
If you see a new entry, do the calculation, send mail and update the completed field.
Is there any way to make Google Script call functions asynchronously? My scenario is that I have a main spreadsheet that information is entered into and a script then passes the relevant information to other spreadsheets.
There are then other functions that manipulate the data in those other spreadsheets. Unfortunately, because of the high volume of data, calling all the functions on one action causes the script to hit the 6 minute time out.
I tried using the onEdit trigger in the other spreadsheets, but it doesn't seem to work unless the sheets are opened by a user.
The way it is just now the user would have to hit 4 different buttons to trigger the various functions and not get a time out.
Thanks for any help
Blair
Depending on how realtime the updates need to be, you could consider creating a queue that contains all of the updates to be made (perhaps stored in the PropertiesService as a stringified JSON object).
Then your update code could be triggered regularly, say every 5 minutes, and read the next element of the queue and execute the update, before removing that entry from the queue. This would mean each individual update fitted within the 6 minute window, but it would also mean that if there were 4 additional updates for every update to the main sheet it might be up to 24 minutes before all of them had been made.
I would like to synchronize a google spreadsheet with a map so that I don't have to upload everything everyday.
I found that it's possible to synch a google form to google map using Google Fusion.
See, YouTube: Syncing Google Forms with Google Fusion Tables for Crowdsourced Maps.
But I couldn't replicate the process to my situation (I guess it's maybe because the spreadsheet content is not originated from a google form and maybe the script take that into account)
I don't know much about coding scripts but automating this process would be a blast for me!!
I hope someone will be able to help me out on this
thanks a lot and have a good day
The only thing to account for this situation is the difference of form submit. The guy in the video sets up two triggers: one for onFormSubmit, and one hourly trigger for syncing whenever any manual changes are made.
I haven't looked directly over the code, but all you should have to do is modify the onFormSubmit code and trigger. Change the code to look for and update the fusion table with any new rows from your spreadsheet. And then change the trigger to your desired need, timer would probably be the best option. So every hour, or day, or run it manually after your done adding rows.
Now, if you were to edit the rows of data after they've already been updated, the hourly syncing will take care of those changes.
I could imagine that the hourly sync method could be changed in such a manner to look for rows that need to be added, could be as simple as calling the submit function.
I had the same problem but i could solve it.
A time trigger is not needed if you set the sync function at the end of the function OnFormSubmit (so "sync();" under "insertRowId(rowId, row);" Syncing takes place after each sending of the form automatically.
For larger forms I found out that you should not make a special column Location in the Fusion table. The address column should marked as Location in Fusion table. In the script properties of the spreadsheet give the addressColumn the value of the column title of the address column and the third property keeps unchanged ("latlng">Location. What happens is that the value of the adres is overwritten by "latlng". So if you have trouble to loose the original addresses, add a new column, copy by apps script the same address (that piece of script direct at the beginning of the function OnFormSubmit) and (after syncing) give the addressColumn the value of the column title and in the Fusion table marks the original addess column as Text and the new column as Location.
I'm new and appreciate help on my question!
My spreadsheet acts as a sales tool, where info is entered in various cells to run sensitivity analysis. Once the salesperson picks a desired option they "submit it". The data submitted is then stored on a separate sheet in the spreadsheet (call it the "database").
I want the database sheet to store all user submissions. The problem is when multiple users are using the sales tool worksheet at the same time, the info they enter gets overwritten by other user's inputs before they can submit.
I'd like multiple users to be able to use the "sales tool" sheet simultaneously without overwriting eachother, but still be able to submit data to the "database" sheet.
Appreciate ideas?
You can use the Lock Service to take a lock on the spreadsheet and then release it once you've written to it.
Besides the Lock Service (already mentioned by Srik) there's the Sheet.appendRow function, which is way easier to use and much faster. But only makes sense if you're inserting new data to a sheet and not really writing to the same cells.
Can't you use a form?
This way people could insert data without actually modify the spreadsheet...