- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 03:57 AM
Hello All,
I know its a very basic doubt, but i am little confused, how to parse the response body and get number from that and update in my incident table field vendor_ticket.
I have a After Insert Business Rule with triggers the POST to another Servicenow instance. I can able to do achieve this task. But upon getting a response, i have to get the number from the response and update that into vendor field.
My After-Insert Business Rule:
try {
var r = new sn_ws.RESTMessageV2('SnowtoSnow', 'POST');
// r.setStringParameter('assignment_group', "Network");
r.setStringParameter('impact', current.impact);
r.setStringParameter('short_description', current.short_description);
r.setStringParameter('caller_id', current.caller_id);
r.setStringParameter('urgency' , current.urgency);
r.setStringParameter('description', current.description);
r.setStringParameter('category',current.category);
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthentication(authentication type, profile name);
var response = r.execute();
var responseBody = response.getBody();
gs.log(responseBody);
var httpStatus = response.getStatusCode();
if (httpstatus == 200 || 201)
{
gs.addInfoMessage("Incident has been raised on target instance");
} else {
gs.addInfoMessage("Transaction Failed");
}
var jsonBody = response.getBody();
var jsonOB = json.parse(jsonBody);
gs.log('Number' = +jsonOB.number);
current.setValue('vendor_ticket' , jsonOB.number);
}
catch(ex) {
var message = ex.getMessage();
}
})(current, previous);
1> Where do i write this Business rule to parse the json response? Is that on the same After-Insert Business rule. Coz In some post i found that this parsing should be on Before BR,
2> Where does this response body gets stored(is there any table), coz if i want to refer a particular response then where should i need to look?
3> In the script i am trying to show message if the status is 200 0r 201, but i can't see the message even the transaction is successful?
Please help me fix these issues..
Thanks a Lot in Advance
Shashikant
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 06:06 AM
Hi Shashikant,
Please find responses below to your question:
1> Where do i write this Business rule to parse the json response? Is that on the same After-Insert Business rule. Coz In some post i found that this parsing should be on Before BR, -> I assume you have after insert BR to trigger the API, in same code you will get the response and you need to parse there itself.
2> Where does this response body gets stored(is there any table), coz if i want to refer a particular response then where should i need to look? - It is not stored anywhere unless you use ecc_queue for request and response. you cannot see the response unless you print it in logs or store the request and response in some custom table so that going forward if any issue you can check for what request what response came in
3> In the script i am trying to show message if the status is 200 0r 201, but i can't see the message even the transaction is successful?
-Can you try to print the http status in logs.
Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
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-30-2018 03:51 AM
Hi Shashikant,
Any update on this?
Can you mark my answer as correct, helpful if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader