2

I've been looking at this "example" in the GAS documentation, but there is no explanation accompanying it from the googlers documenting it:

https://developers.google.com/apps-script/guides/html-service-communication#user_objects

My question pertains to the successhandler and the passing of parameters to the updateButton function. When called in the onclick, the successhandler doesn't include the variables (within the parentheses) in it's call to updateButton. Following the successhandler call is the user object and getEmail but they seem to be out of order (the function updateButton has email before button).

So, how/why does this code work? I've tested it, and even rearranged the variables and what not but the only way it works is in the documentation's writeup. I am unable to understand how the updateButton function knows the parameter values when they are not included in the call to updateButton and they seem to be out of order in the example. Thoughts?

1 Answer 1

1

If I understood your question the return of the getEmail function at your GAS script will be redirect to your sucess Handler. You can try to use Logger.log(Session.getActiveUser().getEmail()) and check the return . The parameters order are first the values returned by the gas function and finally the element which triggered the action.

7
  • 1
    Thanks! yes I think you have the gist of the question. But the order of the listing of parameters - why does it seem to be out of order? isn't the button a variable in its own right - so why does the getEmail return get listed first in: function updateButton(email, button) yet in the successhandler, the getEmail is listed second: .withSuccessHandler(updateButton) .withUserObject(this) .getEmail() Aug 19, 2013 at 18:33
  • You delegate the calls to be made in the correct order. You can also concat the failure handler to this call. .withFailureHandler(onFailure))
    – br araujo
    Aug 19, 2013 at 18:56
  • i don't understand that - are the calls in the successhandler going from right to left? is that what I am missing? Aug 19, 2013 at 18:58
  • the order that you put withFailure and withSuccess doens't matter. Google developers maybe used chain of responsability pattern to make the calls in the right order.
    – br araujo
    Aug 19, 2013 at 19:00
  • okay :-) forget the failure handler - not even thinking about that :-) my problem is understanding the the proper order of the varibales in relation to their calling - in function updateButton(email, button) they go left to right, but in .withSuccessHandler(updateButton) .withUserObject(this) .getEmail() they go right to left - so is that some standard way the functions run from right to left somehow? is that a javascript thing? so if I chain getEmail and getCalEvent, the getCalEvent would be run first (since its on the right) and its return sent first to the successhandler function? Aug 19, 2013 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.