Populate all RITM numbers of selected user in catalog item.

Sai175
Kilo Contributor

Hi,

I have two catalog items,

New Hire - with two variables (requested for (reference) , Model (reference)

find_real_file.png

Another catalog item,

Leaver - with variables(requested for, Request's related to user)

when requested for is selected, all RITM's of the requested user should be populated in another field.

find_real_file.png

Question:

1. what variable type is suggested to populate all RITM's of user.

2. How to achieve this.

Please help me in this.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you need to check the variable value for request on behalf of and not requested_for field

If you just want to display the RITMs then you can use single line text variable and populate the values as comma separated numbers

Use onChange client script + GlideAjax to set the variable present on Leaver catalog item

UI Type - ALL

Applies to Catalog Item - True

Variable - Requested on behalf of

Script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading) {
		return;
	}

	if(newValue == '')
		g_form.clearValue('variableName');

	if(oldValue != newValue){
		var ga = new GlideAjax('getMyRequests');
		ga.addParam('sysparm_name', "checkRecordPresent");
		ga.addParam('sysparm_user', newValue);
		ga.getXMLAnswer(function(answer){
			if(answer != ''){
				g_form.setValue('variableName',answer);
			}
		});
		//Type appropriate comment here, and begin script below
	}
}

Script Include:

var getMyRequests = Class.create();
getMyRequests.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getRequestItems: function(){

		var user = this.getParameter('sysparm_user');
		var arr = [];
		var gr = new GlideRecord("sc_req_item");
		gr.addQuery("cat_item.name", "New Hire"); // name of your catalog item
		gr.query();
		while (gr.next()) {
			if(gr.variables.requested_on_behalf_of == user)
				arr.push(gr.getUniqueValue());
		}

		return arr.toString();
	},

	type: 'getMyRequests'
});

Regards
Ankur

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

View solution in original post

13 REPLIES 13

Hi @Ankur Bawiskar,

Thank you, modified the "it should be getRequestItems and not checkRecordPresent at line 11 in client script"

I've added info message in script include and checked in logs, info message is showing but the RITM's are populating in catalog item.

find_real_file.png

find_real_file.png

find_real_file.png

Hi,

you didn't select any user?

Unless you select user the onChange won't run and won't show the RITMs

Regards
Ankur

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

Hi @Ankur Bawiskar ,

Apologies, i've selected the user, but didn't submitted the New Hire request.

Now i've submitted New Hire request and selected the same user in Leaver form, but RITM numbers are not populating instead sys_id's are populating.

find_real_file.png

Hi,

update as this and it will show RITM numbers

push number into array

arr.push(gr.getValue('number'));

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards
Ankur

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