- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
My requirement is 3rd party wants to create RITM in ServiceNow. I have provided them OOB endpoint:
https://marriottdev.service-now.com/api/sn_sc/servicecatalog/items/{sys_id}/order_now
and JSON as :
{
'sysparm_id' : '4f9131449f901200d54dd4b4232e708d',
'sysparm_quantity' : '1',
'correlation_id': 'ABC-123',
'correlation_display': 'ABC'
'variables':{
'support_group':'DEF',
'u_summary':'test',
'u_detailed_description': 'test1'
}
}
The response I am getting back is :
in the 'request_number' , I am getting the REQ number.
But my client wants the RITM number to display over there instead of REQ number.
How can I achieve this?
The response body
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
try this and also add logs to debug where it's failing
it's telling line 44 and line 50
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var reqbody = request.body.dataString;
try {
var parser = new global.JSON();
var parsedData = parser.decode(reqbody);
var suppGroup = parsedData.support_group;
var uSummary = parsedData.u_summary;
var detailDescr = parsedData.u_detailed_description;
var corID = parsedData.correlation_id;
var corDisplay = parsedData.correlation_display;
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
// give here the sys_id of the catalog item under which those variables are present
var item = cart.addItem('249365f4478cf6109b866e31516d4356', 1);
//fill in the variables on the request item form
cart.setVariable(item, "support_group", suppGroup);
cart.setVariable(item, "u_summary", uSummary);
cart.setVariable(item, "u_detailed_description", detailDescr);
cart.setVariable(item, "correlation_id", corID);
cart.setVariable(item, "correlation_display", corDisplay);
var rc = cart.placeOrder();
// rc is the request number; you can query RITM table and get the RITM number
var reqNumber = rc.number;
var ritm = new GlideRecord('sc_req_item');
ritm.get('request.number', reqNumber);
var ritmNumber = ritm.number;
var res = {};
res["status"] = "Success";
res["requestNumber"] = reqNumber.toString();
res["requestItemNumber"] = ritmNumber.toString();
response.setBody(JSON.stringify(res));
} catch (ex) {
var res1 = {};
res1["status"] = "Error";
res1["message"] = ex.message;
response.setBody(JSON.stringify(res1));
}
})(request, response);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
you can't alter this OOTB behavior
2 Ways
1) ask them to parse and get REQ and then ask them to consume Table API on sc_req_item with encoded query as this
request.number=REQ001
OR
2) create your own scripted REST API which gives you control over what you can send in response
I shared solution here few years ago, check that and enhance
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi @Ankur Bawiskar ,
I tried the script that you have shared in the link but got below error:
{
"error": {
"message": "Script Evaluation Exception",
"detail": "Cannot convert {\"status\":\"Error\",\"message\":\"Cannot convert {\\\"status\\\":\\\"Success\\\",\\\"requestNumber\\\":{},\\\"requestItemNumber\\\":{}} to org.mozilla.javascript.ScriptableObject (sys_ws_operation.ec4250763b347a100057e09a04e45a4a.operation_script; line 44)\"} to org.mozilla.javascript.ScriptableObject (sys_ws_operation.ec4250763b347a100057e09a04e45a4a.operation_script; line 50)"
},
"status": "failure"
}
Below is the script:
Could you please help me to identify the error?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
try this and also add logs to debug where it's failing
it's telling line 44 and line 50
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var reqbody = request.body.dataString;
try {
var parser = new global.JSON();
var parsedData = parser.decode(reqbody);
var suppGroup = parsedData.support_group;
var uSummary = parsedData.u_summary;
var detailDescr = parsedData.u_detailed_description;
var corID = parsedData.correlation_id;
var corDisplay = parsedData.correlation_display;
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
// give here the sys_id of the catalog item under which those variables are present
var item = cart.addItem('249365f4478cf6109b866e31516d4356', 1);
//fill in the variables on the request item form
cart.setVariable(item, "support_group", suppGroup);
cart.setVariable(item, "u_summary", uSummary);
cart.setVariable(item, "u_detailed_description", detailDescr);
cart.setVariable(item, "correlation_id", corID);
cart.setVariable(item, "correlation_display", corDisplay);
var rc = cart.placeOrder();
// rc is the request number; you can query RITM table and get the RITM number
var reqNumber = rc.number;
var ritm = new GlideRecord('sc_req_item');
ritm.get('request.number', reqNumber);
var ritmNumber = ritm.number;
var res = {};
res["status"] = "Success";
res["requestNumber"] = reqNumber.toString();
res["requestItemNumber"] = ritmNumber.toString();
response.setBody(JSON.stringify(res));
} catch (ex) {
var res1 = {};
res1["status"] = "Error";
res1["message"] = ex.message;
response.setBody(JSON.stringify(res1));
}
})(request, response);
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
