Widget Pass data
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 08:36 AM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-23-2024 08:52 AM
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