Wait for REST API Response

kunjangondalia
Tera Contributor

We have a scenario where we have to call a REST API to create new Standard Change (only way create std change). But when creating standard change though API it takes long time and Ideally response body has new change number but sometimes response is undefined  though in change_request table a change is created. We need response as it contains change number and change number is important for rest of the functions/script to run.

 

Thank You.

1 REPLY 1

Vrushali  Kolte
Mega Sage

Hello @kunjangondalia ,

 

You can make use of waitForResponse(seconds) function as below -

var response = r.executeAsync();
response.waitForResponse(60); //pass the seconds to wait
 var responseBody = response.getBody();
 var httpStatus = response.getStatusCode();

 

you can also refer below link for more details -

 

https://www.servicenow.com/community/developer-forum/how-to-wait-the-script-until-receive-response-f...

https://www.servicenow.com/community/now-platform-forum/will-the-function-quot-waitforresponse-secon...

 

If my answer solves your issue, please mark it as Accepted and Helpful based on the impact.