How to ask the REST Response to wait 60 seconds

Rani11
Tera Expert

Hi All,

i have a scenario in one of the integration like.

If i get response as "200" then update the task with state as "closed completed"

else if response get 400 then wait for 60 then update the task as "not successful" in the worknotes.

I have tried like below.. but wait time is not happening. can anyone help me on thisvar response = r.execute();

var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log("Display responsebody"+responseBody);
var requestStringECC = r.getRequestBody();

var requestString=responseBody.toString();
var parser = new JSONParser();
var parsed = parser.parse(responseBody);
if(httpStatus==200){

current.state==3;
current.work_notes = "Status: "+httpStatus+"Successful";
}
else if(httpStatus==400||httpStatus==500){
gs.log("inside 400 blok"+httpStatus);
var res=response.waitForResponse(60);
gs.log("inside response waittime blok"+res);
if(res>60){
gs.log("inside response waittime if blok"+res);
current.state==1;
current.work_notes="Status: "+httpStatus+"Unable toprocess your request"
}
}

Can anyone help to resolve the issue.

 

 

1 ACCEPTED SOLUTION

Hi Rani,

please try this

else if(httpStatus==400||httpStatus==500){
gs.log("inside 400 blok"+httpStatus);

var seconds = 60;

var seconds = parseInt(seconds, 10) * 1000;

var start = parseInt(new Date().getTime()) + seconds;

while(start>parseInt(new Date().getTime())){
// do nothing
}

//var res=response.waitForResponse(60);
gs.log("outside the wwaitblock while loop response w");

current.state==1;
current.work_notes="Status: "+httpStatus+"Unable toprocess your request.";

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

12 REPLIES 12

Hi @Ankur Bawiskar 

What is the system doing during this "wait" of 60 seconds?

When I understand your code right, it will just race around doing nothing than burining the processor and consuming system resources.

Even that I have no better idea to solve this, would it be a good idea to slow down the instance while doing noting?

If that happens more often, this may have a big impact on your overall system performance. Don't you think so?

BR

Dirk

Hi Dirk,

I agree. Even I was about to check the business use-case/requirement around this and it missed.

Probably this needs to be checked by Rani with their business team on why it is required

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Rani11
Tera Expert

Hi Ankur,

Thank you so much . It is working as expected.