We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

How to get the list(array) request item numbers according to the item name in sc_req_item

Bowen Lu
Tera Contributor

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.

jsキャプチャ.PNG

 

1 ACCEPTED SOLUTION

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

@Bowen Lu 

Glad to know.

Please mark response helpful as well.

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader