- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 08:24 AM
Hi All,
I have situation where i need to make two outbound call. The second call is based on the first call result. Now when trigger second call i got below error:
Cannot find function getStatusCode in object [object RESTMessageV2].
I couldn't find anything related to this. Does anyone has any idea about it.
Thanks in Advance.
Solved! Go to Solution.
- Labels:
-
Orchestration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 08:35 AM
Few points:
1) you should be using the getStatusCode() method on the response you received.
2) It seems you are applying it on object of RESTMessageV2
3) Also are you doing this in scoped app then it would throw this error
I just tried this and it throwed me error when I used that on object of RESTMessageV2
Sample script below:
try {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
request.setEndpoint('<web service endpoint URL>');
request.setRequestBodyFromAttachment('<attachment sys_id>');
var response = request.execute();
// this would work fine as you are using response
var httpResponseStatus = response.getStatusCode();
// this will throw error as you are using it on request object
var httpResponseStatus = request.getStatusCode();
gs.info("http response status_code: " + httpResponseStatus);
}
catch (ex) {
var message = ex.getMessage();
gs.info(message);
}
Output: When I tried to use RESTMessageV2 in scoped app from background and used request object to get the status code; I also received the same error
So you should use that on response variable.
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
07-14-2020 08:35 AM
Few points:
1) you should be using the getStatusCode() method on the response you received.
2) It seems you are applying it on object of RESTMessageV2
3) Also are you doing this in scoped app then it would throw this error
I just tried this and it throwed me error when I used that on object of RESTMessageV2
Sample script below:
try {
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('post');
request.setEndpoint('<web service endpoint URL>');
request.setRequestBodyFromAttachment('<attachment sys_id>');
var response = request.execute();
// this would work fine as you are using response
var httpResponseStatus = response.getStatusCode();
// this will throw error as you are using it on request object
var httpResponseStatus = request.getStatusCode();
gs.info("http response status_code: " + httpResponseStatus);
}
catch (ex) {
var message = ex.getMessage();
gs.info(message);
}
Output: When I tried to use RESTMessageV2 in scoped app from background and used request object to get the status code; I also received the same error
So you should use that on response variable.
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
07-14-2020 09:31 AM
Hi Ankur,
Thank you for the quick response. I overlooked that part. It works now.
Regards
Gaurav