Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Widget Pass data

ican
Tera Contributor

Use Case:

I want to pass data from widget client script to server script then after server script finished executing pass data from server script to client script.

Widget Client Script:

c.data.name = "test";

c.server.update().then(function() { c.data.name = undefined ; })

 

Server Script:

if(input.name = "test") {

data.name = "new test";

}

 

i want to get the new value of data.name in client script after the c.server.update() call.

1 REPLY 1

Satishkumar B
Giga Sage
Giga Sage

Hi @ican 
Widget Client Script

 

 

// Set initial data
c.data.name = "test";

// Call the server script with the current data
c.server.update({
    name: c.data.name
}).then(function(response) {
    // Update client-side data with the response from the server script
    c.data.name = response.name;
});

 

 

Server Script

 

 

(function() {
    // Retrieve the input data
    var inputName = input.name;

    // Initialize an object to store the output
    var output = {};

    // Check if input.name matches the condition
    if (inputName === "test") {
        // Update the output object with new data
        output.name = "new test";
    } else {
        // If condition does not match, return the original input
        output.name = inputName;
    }

    // Return the output data to the client script
    return output;
})();

 

 

 

……………………………………………………………………………………………………

Mark this as Helpful👍 / Accept the Solution✔️ if this helps