- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2016 01:59 PM
Is it possible to call the server code from the client controller? I want to be able to do this so I can poll in widget I'm creating. I know I can do this by polling a REST service, but I'd rather use what's within the widget if possible.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2016 02:44 PM
Hi Dan,
Check out this doc: Client and server scripting
From the Client Controller you can use c.server.update() (assuming you are using the controller as syntax). This will then call the Server Script in the widget. Of course the issue here is that the Server Script is then called both on request and again on AJAX calls. To distinguish, add an if check in the Server Script for the input variable which contains the AJAX data.
Server Script Example
if (input) {
// AJAX from c.server.update()
}
else {
// Initial load
}
If you check existing widgets, you will find this if (input) pattern.
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2016 02:44 PM
Hi Dan,
Check out this doc: Client and server scripting
From the Client Controller you can use c.server.update() (assuming you are using the controller as syntax). This will then call the Server Script in the widget. Of course the issue here is that the Server Script is then called both on request and again on AJAX calls. To distinguish, add an if check in the Server Script for the input variable which contains the AJAX data.
Server Script Example
if (input) {
// AJAX from c.server.update()
}
else {
// Initial load
}
If you check existing widgets, you will find this if (input) pattern.
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2016 06:08 AM
Yup. That totally works and actually was what I was doing. I was having a problem somewhere else.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2016 12:33 AM
Hi Dan- Can you please let me know how you have implemented polling mechanism? I have similar requirement where I am displaying the list through REST call and I have to poll this so that widget keep refreshing at particular interval.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2016 08:56 AM
I noticed this does in fact call twice, can you tell me the difference between the server.update() and the server.get() methods. I noticed with the get() method it doesn't call twice and seems to be a nicer syntax:
c.deleteTask = function(sys_id) {
c.server.get({
action: "deleteTask",
sysId: sys_id
}).then(function(response) {
});
You get a lot more back on the response too.
Cheers
Martin