The CreatorCon Call for Content is officially open! Get started here.

Rest Response need to wait

Dilip Puligilla
Giga Guru

Hi All

How to make my rest call to wait until it responds. since the web service will responds after some time. I am using asynchronous Calls. Could you please suggests how to make it wait.

I tried

setHttpTimeout(10000),

waitForResponse(60).

The Problem is , I couldn't able to finish the request until it responds, i mean it taking too long to submit the service catalog request.

1 ACCEPTED SOLUTION

An Event has two parameters you can use to pass values.


gs.eventQueue('event_name', current, 'parm1', 'parm2');



If you need to pass more values, and you're familiar with JavaScript Objects, you can always pass a JSON string.


gs.eventQueue('event_name', current, '{"name1":"value1","name2":"value2","name3":"value3"}', 'parm2');



Then from your Script Action, you call the parameters like this (assume parm1 is a User's sys_id):


var user = new GlideRecord('sys_user');


if (user.get(event.parm1)) {


        // Do stuff here


}


View solution in original post

8 REPLIES 8

Do you have to wait for the response? Are you waiting to get information back before you can continue? Or can you just "fire and forget"?


One "fire and forget" method I use is as follows:


  • Register an event, say integration.delete_service
  • In your existing Business Rule, just fire the event (don't trigger the web service)
  • Create a Script Action that runs when the event is processed.   The Script Action calls or executes the web service.


Since events are processed asynchronously, this means that the the form is not waiting for the web service to finish. It will submit as soon as the event is fired, so pretty much instantly. The web service is calls soon after, but you're not waiting on it.



If you do have to wait for the web service to complete because you need information from it, then you're out of luck.




Hi Geoffrey Sage



Thanks for your reply!!



It seems like it working, I have one question, I need to pass some variable values to Script action, can I know how can I pass the variable values to script action . once value comes into Script action   I need to glide record to get another value from the table to generate a query for my rest Request.


An Event has two parameters you can use to pass values.


gs.eventQueue('event_name', current, 'parm1', 'parm2');



If you need to pass more values, and you're familiar with JavaScript Objects, you can always pass a JSON string.


gs.eventQueue('event_name', current, '{"name1":"value1","name2":"value2","name3":"value3"}', 'parm2');



Then from your Script Action, you call the parameters like this (assume parm1 is a User's sys_id):


var user = new GlideRecord('sys_user');


if (user.get(event.parm1)) {


        // Do stuff here


}


Thank you very much