Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Widget Pass data

ChezAndrewI0898
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

Hi @ChezAndrewI0898 
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