Need to update Opened By in RITM via REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 02:35 AM
Hi,
I have created a REST API which is a POST API, and it will create the RITM data in Requested Items list. With these items I need to pass the Opened by name of the person logged in. When I tried to modify the API by adding the "opened_by" field it takes the default system administrator.
Any leads to resolve this will be highly appreciated.
Thanks
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 07:43 AM
Hi,
I don't think it will happen unless they send some information in it i.e. the json object
because that is the only place where ServiceNow could determine what to populate from what.
Did you check the log for obj.opened_by what it comes in the json object they send?
it is their responsibility to send correct details so that you can populate the opened_by
Also I believe they won't send the sys_id of the user; they might be sending the name
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
‎09-06-2019 03:24 AM
Hi,
As suggested I added the log in my code and on running the POST function, the log is providing me the correct value as expected. But, the OOTB Opened By field on the RITM is getting populated with the default as sys admin instead of the value that is passed.
Even I have created a custom field "Opened By" on the RITM table, but here also I'm getting the same issue as mentioned above.
Please suggest if there is any way out.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 02:41 AM
Hi,
Are you using system admin for integration?. You can make requested for to the person who is logged in.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 03:20 AM
Hi Ashutosh,
Yes I'm using System Admin for integration. But I want the "opened_by" field on the RITM to be populated with the logged in credentials of third party user who is raising the request.
Please find my code below:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try{
var obj = request.body.data;
var sys = new GlideRecord('sc_cat_item');
sys.get('name',obj.item_name);
gs.info('test cat'+ sys.name);
var cat = sys.sys_id.toString();
gs.info('what is sys id '+ cat);
var a = processCart(cat, obj);
var item = getRequestNum(sys.sys_id.toString());
return {
'number':item
};
}
catch(e){
gs.info('Something wrong with request paramaters' + e);
}
function getRequestNum(sys_id){
try{
var number ='';
var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item',sys_id);
gr.orderByDesc('number');
gr.query();
if(gr.next()){
gs.info('Item to return ' + gr.number);
}
else{
gs.info('Item to return does not exists' + gr.number);
}
gs.log('Number is:Sheveta'+number);
return gr.getDisplayValue('number');
}
catch(e){
gs.info('Error in response' + e);
}
}
function processCart(cat, obj){
var a;
try{
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem(cat);
if(obj.item_name == 'Teams Creation')
{
cart.setVariable(item, 'team_name' , obj.team_name);
cart.setVariable(item, 'team_owner' , obj.team_owner);
cart.setVariable(item, 'team_description' , obj.team_description);
cart.setVariable(item, 'team_duration' , obj.team_duration);
cart.setVariable(item, 'access_type' , obj.access_type);
cart.setVariable(item, 'opened_by' , obj.opened_by);
}
var rc = cart.placeOrder();
ak = ('rc' + 'Info of cart');
}
catch(e){
a = ('log cart error '+ e);
}
return a;
}
})(request, response);
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-04-2019 03:06 AM
It takes the user that is used for integration. Are you using admin account for integration?