Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 03:56 AM - edited 10-03-2022 04:05 AM
Hi I want to how to write the scripted REST API to get the list numbers of request items.
Expect output:
requestItems = ["RITM12345", "RITM23456"]
query param = "title example"
Thanks in advance.
Solved! Go to Solution.
1 ACCEPTED SOLUTION
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 04:45 AM
script will look like this
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
try {
var arr = [];
var itemName = request.pathParams.itemname;
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("cat_item.name", itemName);
ritm.setLimit(2);
ritm.query();
while(ritm.next()) {
arr.push(ritm.getValue('number'));
}
var responseBody = {};
responseBody.data = arr;
responseBody.status = "Success";
response.setBody(responseBody);
}
catch (ex) {
var message = ex.message;
}
})(request, response);
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2022 06:19 AM
Glad to know.
Please mark response helpful as well.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader