- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 08:50 AM
Hi There,
I have written one Scripted Rest API and passed that information to Postman application to create a new Request but in RITM the reference fields value is not populating (Requestor field value is not populating)
for getting Requestor field value i have written one script Include and and called that script include in Scripted rest API
but in Postman I'm getting an Error, please find the Script Include and Scripted Rest API below
Script Include :
var ceredianUtility = Class.create();
ceredianUtility.prototype = {
initialize: function() {},
getRequestorSysid: function(reqname) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name',requestor);
gr.query();
if (gr.next()) {
gr.sys_id;
return true;
}
},
type: 'ceredianUtility'
};
Scripted Rest API:
var error = '';
var catItem = '';
var cat = new GlideRecord('sc_cat_item');
if (cat.get('name', 'Hire/Transfer')) {
catItem = cat.sys_id;
}
var cart = new Cart();
var item = cart.addItem(catItem);
var requestersysid = new ceredianUtility.getRequestorSysid(request.body.data.requestor);
var cartGR = cart.getCart();
cartGR.update();
var rc = cart.placeOrder();
response.setBody({
result: 'Catalog Item request' + rc.number + 'created.'
})
cart.setVariable(item, 'requestor', requestersysid);
but in Postman when i Run, at that time, im getting below Error
"error": {
"message": "undefined is not a function.",
"detail": "TypeError: undefined is not a function. (sys_ws_operation.e2121c77c3107590daff4f45df0131a9.operation_script; line 14)"
},
"status": "failure"
Can somebody please help me, in my code where i'm doing wrong, someone please help me
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 09:30 AM - edited 08-08-2023 09:36 AM
Hello @Community Alums ,
Firstly your script include you are returning a boolean value as the output in your function instead of returning the sys_id of the user.
Secondly you are querying it with wring parameter name. as "requestor".I think it should be reqname
Thirdly in your cart API script you missed parenthesis while calling your script include.please try below line
var requestersysid = new ceredianUtility().getRequestorSysid(request.body.data.requestor);
Please try the below script
Script Include :
var ceredianUtility = Class.create();
ceredianUtility.prototype = {
initialize: function() {},
getRequestorSysid: function(reqname) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name','requestor');
gr.query();
if (gr.next()) {
return gr.sys_id.toString();
}
},
type: 'ceredianUtility'
};
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 09:30 AM - edited 08-08-2023 09:36 AM
Hello @Community Alums ,
Firstly your script include you are returning a boolean value as the output in your function instead of returning the sys_id of the user.
Secondly you are querying it with wring parameter name. as "requestor".I think it should be reqname
Thirdly in your cart API script you missed parenthesis while calling your script include.please try below line
var requestersysid = new ceredianUtility().getRequestorSysid(request.body.data.requestor);
Please try the below script
Script Include :
var ceredianUtility = Class.create();
ceredianUtility.prototype = {
initialize: function() {},
getRequestorSysid: function(reqname) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name','requestor');
gr.query();
if (gr.next()) {
return gr.sys_id.toString();
}
},
type: 'ceredianUtility'
};
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 11:30 PM
Hi @Mohith Devatte,
Thanks for your response,
I have written the script include as you mentioned, but the Function name 'reqname' is becoming read only
and the value in not reading,
please check the snap shot attached.
In the first Snap shot Green Underlined value is not reading.
so could please help me why that function name is not reading and becomes read only.
What may be the solution.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2023 11:39 PM - edited 08-08-2023 11:41 PM
Hello can you modify your script include like below
getRequestorSysid: function(reqname) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name',reqname); // if reqname value is name then you can use name if it return sysid then you need to use 'sys_id' instead of 'name'
gr.query();
if (gr.next()) {
return gr.sys_id; // return user sysid
}
},
Harish