caling script include in scripted rest api but script was not working it's showing syntax error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 08:35 PM
i need to created one custom API using GET method and caling script include in scripted rest api but script was not working it's showing syntax error
script include:
this.user is already set on constructor
// Check services by get ritms
getRITMsByRequestedFor: function() {
var responsejson = {};
var tableritms = [];
var ritms = new GlideRecord('sc_req_item');
ritms.addEncodedQuery("requested_for=" + this.user + "^stateIN-5,1,2,9,11");
ritms.query();
while (ritms.next()) {
var ritm = {};
ritm.number = ritms.number.getDisplayValue();
ritm.item = ritms.cat_item.getDisplayValue();
ritm.requested_for = ritms.requested_for.getDisplayValue();
ritm.state = ritms.state.getDisplayValue();
ritm.email = utils.user.email;
tableritms.push(ritm);
responsejson.requested_item = tableritms;
return JSON.stringify(responsejson);
}
},
scripted rest api script:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var uservalue = null;
var ordered = {};
//var item = request_body.user_id;
if (request.queryParams.user_id)
uservalue = request.queryParams.user_id[0];
// check user and
var api_catalog = new global.CAPApiCatalog('API_CATALOG', uservalue, request_body);
// check and set Catalog item on cart
api_catalog.setItem();
ordered = api_catalog;
return {
requested_items: ordered
}
}catch (error) {
response.setError(new sn_ws_err.BadRequestError('syntax error in request body'));
}}
)(request, response);
please anyone help me with mistake
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 10:23 PM
Hi.
Did you see my other comments and suggestions around logging the error and checking what request_body is? That will help resolve your issue I think.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2024 10:46 PM
i used to logging error to check what is the value of
request_body
,
even script include function as well everything it's showing undefined