Scripted REST Resource
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 09:18 AM
Hello Everyone
I have created the following Scripted REST Resource to get the information about Priority -1 Incidents:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var table = 'incident',
result_arr = [],
gr = new GlideRecord(table);
gr.addQuery('priority', 1);
gr.query();
while (gr.next()) {
var result = {};
result.short_description = gr.short_description;
result.number = gr.number;
result.state = gr.state;
result.opened_at = gr.opended_at;
result.location = gr.location.getDisplayValue();
result.email= gr.email;
result_arr.push(result);
}
return {
"Result":result_arr,
};
})(request, response);
When I try to get the response in REST API Explorer , I get the following message:
{
"result": "",
"error": {
"message": "Cannot map object",
"detail": "Cannot map object Check logs for error trace or enable glide.rest.debug property to verify REST request processing"
},
"status": "failure"
}
Please assist me to resolve this issue.
Thanks in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 10:45 AM
Hi Madhusudan,
Have you tried just returning result_arr, rather than including inside another object? I'm look at the simple returns in the demo scripted APIs. Just wondering.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 10:55 AM
Look at some of the OOB processors that utilize a script. There is a third object, processor, that is used to write the output back.
Something like this line
g_processor.writeOutput("application/json", new global.JSON().encode(status));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 10:58 AM
Hi Chris,
Looks like Madhusudan is using a scripted REST API, rather than a processor. Scripted REST APIs give you better security control because they employ the ACLs for the account being used rather than a separate ACL for the processor, allow for versioning of the API, and better URL parameters. They were introduced in Geneva and highly recommended as a replacement for what many people previously did with processors. They don't make use of the g_processor object. I encourage you to check them out.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 11:43 AM
return {
"Result":result_arr,
};
Should be
return {
"Result":result_arr
};
This is without the comma at the end, after the "result_arr".