1

Having trouble getting GAS to execute functions in the order I need. In this code:

function documentUpload(e) {
  var app = UiApp.getActiveApplication();
  app.getElementById('documentValue').setText('Uploaded');
  app.getElementById('documentValueLabel').setStyleAttribute('color', 'black');
  checkSubmit(e);
  return app;
}

...it always runs checkSubmit before changing the text. Which is useless because one of the things that checkSubmit checks is whether documentValue has text.

I saw this post and tried adding LockService like so:

function documentUpload(e) {
  var app = UiApp.getActiveApplication();
  app.getElementById('documentValue').setText('Uploaded');
  app.getElementById('documentValueLabel').setStyleAttribute('color', 'black');
  var lock = LockService.getPrivateLock();
  lock.waitLock(10000);
  checkSubmit(e);
  lock.releaseLock();
  return app;
}

...but I'm not getting any different results. Same thing for Utilities.sleep().

Thanks in advance for any suggestions!

Community
  • 1
  • 1
Finn Smith
  • 772
  • 2
  • 7
  • 21

1 Answers1

0

the UI is updated when you return app . That means that any function call from inside your function cannot see the changes you made to your UI from inside the same function.

You'll have to think differently, ie probably split your code in 2 functions to allow to return the app (in other words to update the UI) before calling the function that reads its content.


EDIT : when I look at your code it seems that the only thing you want to do before starting the download is to change a text value and a style attribute... if so you can use a clientHandler that will execute immediately (see this other recent post) maybe this can solve your problem... let us know if it does.

Community
  • 1
  • 1
Serge insas
  • 45,904
  • 7
  • 105
  • 131