How to access ritm variables (variables used in catalog item) using catalog client script?

Naveen Kumar
Tera Contributor

I need to access the ritm variables in the catalog client script.

there is a field called "Select RITM" referencing sc_req_item in one of the catalog  item.

When a user selects an ritm from the above field, there should be an alert for "Billing rate" field value in that ritm selected.

Billing rate field is on the catalog item,its not on the ritm form.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onChange + GlideAjax

onChange catalog client script on that variable "Select RITM"

UI Type - ALL

Applies on Catalog Item - True

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


	if(oldValue != newValue){

		var ga = new GlideAjax('checkRecords');
		ga.addParam('sysparm_name', "checkRecordPresent");
		ga.addParam('sysparm_ritm', newValue); // give here user_id variable name
		ga.getXMLAnswer(function(answer){
			if(answer != ''){
				alert("Billing Rate Value is " + answer);
			}
		});
		//Type appropriate comment here, and begin script below
	}
}

Script Include: It should be client callable

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

	checkRecordPresent: function(){

		var id = this.getParameter('sysparm_ritm');			

		var gr = new GlideRecord('sc_req_item');
		gr.addQuery('sys_id', id);
		gr.query();
		if(gr.next()){
			return gr.variables.billingRateVariableName;  // use valid variable name here
		}
	},

	type: 'checkRecords'
});

Regards
Ankur

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

View solution in original post

11 REPLIES 11

Ivan Betev
Mega Sage
Mega Sage

Hello Bharath,

have you tried current.variables.<variable name>?

Regards, Ivan

Hi,

I cannot use current, because I am not writing the code for the current ritm record.

My question is :

 

How to access RITM variables via script when your RITM is not the current record.

 

Vasantharajan N
Giga Sage
Giga Sage

Please use g_form.getValue("variable_name")


Thanks & Regards,
Vasanth

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use onChange + GlideAjax

onChange catalog client script on that variable "Select RITM"

UI Type - ALL

Applies on Catalog Item - True

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


	if(oldValue != newValue){

		var ga = new GlideAjax('checkRecords');
		ga.addParam('sysparm_name', "checkRecordPresent");
		ga.addParam('sysparm_ritm', newValue); // give here user_id variable name
		ga.getXMLAnswer(function(answer){
			if(answer != ''){
				alert("Billing Rate Value is " + answer);
			}
		});
		//Type appropriate comment here, and begin script below
	}
}

Script Include: It should be client callable

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

	checkRecordPresent: function(){

		var id = this.getParameter('sysparm_ritm');			

		var gr = new GlideRecord('sc_req_item');
		gr.addQuery('sys_id', id);
		gr.query();
		if(gr.next()){
			return gr.variables.billingRateVariableName;  // use valid variable name here
		}
	},

	type: 'checkRecords'
});

Regards
Ankur

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