- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:00 AM
Hello All,
When I am trying to post the data using json, the value for requested_for reference field is not showing the name its showing has empty.
If I am posting the data using sys_id of the user then it is taking up and showing the correct value.
Could you please help me on this issue, when i try to insert with name, then it will show the name of the user in reference field.
Please help me on below code
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var reqbody = request.body.dataString;
try {
var parser = new global.JSON();
var parsedData = parser.decode(reqbody);
var requestedFor = parsedData.requested_for;
var assignmentGroup = parsedData.assignment_group;
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('afb8ddb7137dab0046d252722244b009', 1); //Catalog item name
//fill in the variables on the request item form
cart.setVariable(item, 'requested_for', requestedFor);
cart.setVariable(item, 'assignmentGroup', assignment_group);
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;
res["requestItemNumber"] = ritmNumber;
response.setBody(res);
} catch (ex) {
var res = {};
res["status"] = "Error";
res["message"] = ex.message;
// response.setBody(JSON.stringify(res));
response.setBody(res);
}
})(request, response);
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 07:14 AM
added this two lines which palani suggested
var grUser = new GlideRecord('sys_user');
grUser.get('user_name',requestedFor);
It working fine now
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:47 AM
I am Pushing the data dynamically using REST API Explorer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:53 AM
can you post the screen shot how you. are trying to push the data or paste the data in REST API explorer to hit the api?
so you are using REST API explorer where you are trying to paste the data manually in the fields and trying to hit the API which in turn tuns your script you pasted below to insert RITM's and requests through cart api.
If this is the case and my assumption is correct i think you need TO paste THE SYS_ID IN THE JSON for this as there is not alternative for reference fields to accept the data
to close the thread please mark this answer correct or if not let me know how i can help

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:23 AM
Hi,
Have you created variable named Requested For? or are you using the OOB field available in Request table?
Thank you,
Palani
Palani
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2022 06:32 AM
I posting the data using JSON