- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 06:37 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 07:43 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 06:48 AM
Hi
Maybe your code just crashes at the following line:
var requestStringECC = r.getRequestBody();
Did you define the variable "r"? I cannot see what it could look like, so this may throw an error.
Let me know if tha solved your issue and mark my answer as correct and helpful.
BR
Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 06:51 AM
Hi,
var requestStringECC = response.getRequestBody();
Thanks
Sudhanshu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 06:52 AM
Yes R has been defined . This is a business rule which i am calling REST Message to send the payload to third party.
So "r" has been defined and its working. Its not an issue. The wait time part alone i am not sure how it should work or how to configure. If i get any help on that would be great..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 06:56 AM
Two options:
gs.sleep(60000);
Or async alternative you can check this one as well.
gs.log('Started','Async example '+ Date.now());
var so = new ScheduleOnce();
so.script = "(function(){gs.log('I waited 60 seconds','Async example '+ Date.now())})()";
so.setAsSeconds(60);
so.schedule();
gs.log('Ended','Async example '+ Date.now());