Luis
Luis

Reputation: 25

Label text binding with call function and no return value

I have an issue with modifying a label text by calling a function (client script) that call a function (server side) with a return value.

A console.info(return value) show the correct value but the label text is empty. Even if a make a return like this ==> return "Test", it doesn't work.

Here is my functions created for debug purposes :

ClientScript :

function onSuccess(value) {
  console.info("debug : " + value); // <== this works !
}

function TestFunction(value) {
  // Call server side functions
  google.script.run.withSuccessHandler(onSuccess).test("any value");

}

ServerScript :

function test(arg) {
    return "This a return value";
}

Binding in label text :

TestFunction("test")

Do you have any idea? What am I doing wrong?

Edit : as ask by Chris, here is the link to the export app zip : https://drive.google.com/file/d/1LEcEYtv0guC_ELicE9vFrY8AygJeVqWP/view?usp=sharing

Upvotes: 0

Views: 656

Answers (1)

Morfinismo
Morfinismo

Reputation: 5253

The problem is you are trying to get the value directly from the server script. As how you see, the console log is working because you are passing the value to the client on the onSuccess function.

What you need to do is pass the widget to the TestFunction and the onSuccess function should go inside the test function. Take into consideration the example below:

ClientScript:

function TestFunction(widget, value) {

  function onSuccess(value) {
    console.info("debug : " + value);
    widget.text = value;
  }

  // Call server side functions
  google.script.run.withSuccessHandler(onSuccess).test(value);

}

ServerScript:

function test(arg) {
    return arg;
}

Binding in label text:

TestFunction(@widget, "This is what I want")

I hope this helps!

Upvotes: 2

Related Questions