0

I have created a shared Google spreadsheet which has two buttons on it which are assigned to functions. One button is intended to be clicked by one person and the other by another person.

Each button will trigger a separate macro which will update the same data in an incremental manner. It is very important that the two macros do not run simultaneously because this will cause the data to become muddled.

If both people clicked on their buttons at exactly the same time, is there a risk that both functions will run simultaneously or will they be automatically queued? Is there a way I can force them to be queued?

What if there are three or more buttons with three or more macros? Will they be automatically queued if clicked simultaneously?

Please note that I don't want to have to resort to creating "busy, try again" messages for the users and I want any queuing process to be invisible to the users.

Rubén
  • 34,714
  • 9
  • 70
  • 166
tim.tub
  • 69
  • 2
  • 7
  • You can use the [LockService](https://developers.google.com/apps-script/reference/lock/lock-service) to prevent that. – Marios Feb 18 '21 at 22:00
  • Thank you, Marios, very much for the link. Unfortunately, the page does not make it clear how to use the commands it mentions. Can you point me towards any examples of usage? – tim.tub Feb 18 '21 at 22:18
  • Put both functionalities into the same function definition and use lock service to insure that only one functionality occurs at a time – Cooper Feb 18 '21 at 22:27
  • Thank you, Cooper. Just to be clear, will this queue the functions so that each user will only have to click their buttons once or will they have to try again? Will the queuing be invisible so they won't notice it? – tim.tub Feb 18 '21 at 22:50

1 Answers1

1

If two or more users clicks a button that has assigned a Google Apps Script function at the same time an execution will be created for each of them and they could "clash". This depends of what is done by these functions.

To prevent this you could you use the Lock Service.

Related


NOTE: In Google Sheets macros is a special type of spreadsheet automation. They are created by using the macro recorder of by importing Google Apps Script functions as macros.

Rubén
  • 34,714
  • 9
  • 70
  • 166