- 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
Hi @Ankur Bawiskar ,
I have modified the script accordingly and its working now.
Thanks a lot for your help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @User205031
I hope you have used the below code :-
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var res = {};
try {
var body = request.body.dataString;
var data = JSON.parse(body);
var suppGroup = data.support_group;
var uSummary = data.u_summary;
var detailDescr = data.u_detailed_description;
var corID = data.correlation_id;
var corDisplay = data.correlation_display;
// Create a new Cart and add item
var cart = new sn_sc.CartJS();
var cartDetails = cart.orderNow('249365f4478cf6109b866e31516d4356', 1, {
'variables': {
'support_group': suppGroup,
'u_summary': uSummary,
'u_detailed_description': detailDescr,
'correlation_id': corID,
'correlation_display': corDisplay
}
});
// cartDetails returns an object with request_id and request_number
if (cartDetails.request_id) {
var reqGr = new GlideRecord('sc_request');
if (reqGr.get(cartDetails.request_id)) {
var reqNumber = reqGr.number.toString();
// Get the first RITM under this request
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('request', reqGr.sys_id);
ritm.orderByDesc('sys_created_on');
ritm.query();
var ritmNumbers = [];
while (ritm.next()) {
ritmNumbers.push(ritm.number.toString());
}
res.status = "Success";
res.requestNumber = reqNumber;
res.ritmNumbers = ritmNumbers;
} else {
res.status = "Error";
res.message = "Request not found for returned ID.";
}
} else {
res.status = "Error";
res.message = "Order creation failed.";
}
} catch (ex) {
res.status = "Error";
res.message = ex.message;
}
response.setBody(JSON.stringify(res));
})(request, response);
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
YouTube: https://www.youtube.com/@learnservicenowwithravi
LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@User205031 I dont think this is possible with the current end point.
Workaround:
After receiving this response they will have to make on additional GET call to sc_req_item table with sysparm_query=request.number="" // pass the request number received in earlier call
/api/now/table/sc_req_item?sysparm_query=request.number=REQ0010042
Please mark the answer correct/helpful accordingly.
