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

Dilip Puligilla
Giga Guru

anyone, please does suggest me


Hi Dilip,


As per this documentation link waitForResponse(60); could be the right choice for you.


Asynchronous RESTMessageV2 example


..


response.waitForResponse(60);// In seconds. Wait at most 60 seconds to get response from ECC Queue/Mid Server //Might throw exception timing out waiting for response in ECC queue.
..



Are you checking the response ? If so what is the response?


..
responseBody
= response.haveError() ? response.getErrorMessage() : response.getBody();


..


Best Regards



Tony


Geoffrey2
ServiceNow Employee
ServiceNow Employee

Hi dilip,


Can you describe your scenario a bit more, step by step? I'm not sure what you're doing or what the issue is.


It sounds like a REST web service is triggered when you submit a Catalog Item, but it's causing the form to take too long to submit. Is that correct?


How are you triggering the web service?


Dilip Puligilla
Giga Guru

Hi Geoffrey,



Thanks for your email!



let me explain,


I have a Catalog item which trigger's a Rest service to delete a service. since Delete takes extra time my Rest service is not able to respond quickly, it takes 2-3 minutes to get the response.



here the problem , once order button clicked , my screen is frozen for 2-3 until it responds, to over that what can I do!



I have used a business rule to make to trigger service, also tried client script and script include by no luck