ServicePortal call server from client controller?

dmfranko
Kilo Guru

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.

1 ACCEPTED SOLUTION

tltoulson
Kilo Sage

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


View solution in original post

6 REPLIES 6

I know this is old, but for anyone that is looking, this other post answers this question.



server.update() vs server.get()


Thankyou for this. I am new to service portal and this just saved me !