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

@Ankur Bawiskar I know this has already been answered, but I am so close.  How can we add a getXMLWait in the client script portion of this?  I am using return false; in my client script and it's moving to quickly to stop the submission.

//Getting Gap Review Detail Variable
	var ga = new GlideAjax('checkRecords');
	ga.addParam('sysparm_name', "checkRecordPresent");
	ga.addParam('sysparm_ritm', ritmSysID); // give here user_id variable name
	ga.getXMLAnswer(function(answer){
	if(answer != ''){
			alert("OLD GAP OWNER VALUE: " + orig_val + " | GAP OWNER VARIABLE DATA: " + answer);
			if(orig_val != answer){
				alert("THEY DO NOT MATCH - SOMEONE ELSE UPDATED THEIR TASK");
				return false;
			}
		}
	});
	//Type appropriate comment here, and begin script below

Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

@Steven Parker 

are you using the GlideAjax in onSubmit and it's not waiting till the response?

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

That's correct and thanks for the reply, but I figured it out using the KB from ServiceNow:

 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0783579 


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

@Ankur Bawiskar 

One last question....is it possible to modify the script include so that you don't hard code the variable to return?  Maybe pass the variable name in a parameter from the client script to the Script Include?

This way the script include can be reusable by other client scripts.


Please mark this response as correct and/or helpful if it assisted you with your question.
Steven

@Steven Parker 

I don't think so since every validation might be different which you are planning to do in script include function

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