Fetch 'Template values' from sys_template table and store the values in catalog item fields.

Akanksha Rawoo1
Tera Contributor

My Requirement is I have a field called 'Select Template' on a catalog item which is reference field to sys_template table. When I select any template the template values should be auto populated in catalog item fields on catalog form.

i wrote below catalog client script:

function onChange(control, oldValue, newValue, isLoading) {
if(isLoading || newValue == ''){
return;
}
var template = g_form.getValue('Template');
if(template != '')
//Apply the selected template
 applyTemplate(template);

}

But this is not working as expected. Since the template values are stored as XML attached in the screenshot. I want to extract the values from template values and split them separately to populate the values in catalog item fields.

Finally I want to populate catalog item fields whenever I select a template.

Please can anyone help me out to write catalog client script?

5 REPLIES 5

Swapnil Shirsik
Giga Guru

This might help-

 

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


var reg = g_form.getReference('variable', callBackMethod); // your variable name here

}

function callBackMethod(ref){

var str = ref.template; //this should give you the encoded query

var categoryValue = str.substring(str.indexOf('category=') + 9, str.indexOf('^'));

var platformValue = str.substring(str.indexOf('u_platform=') + 11, str.indexOf('^'));

alert(categoryValue);

alert(platformValue);



}

 

https://community.servicenow.com/community?id=community_question&sys_id=75d1445edbb95010b1b102d5ca96197c

My instance has restriction for getReference and GlideRecord operations in catalog client script.

I want to achieve it using other logic.

Since I am getting the sys_id of the template applied in alert, I want to query the table and fetch template values to populate in the fields.

I think, gliderecord is necessary to query a table, we use some conditions such as gr.addQuery() , gr.Query() to query the table through GlideRecord.

You may store the values in script include and then call it from client script. Just curious to know, how is it possible to have restriction of gliderecord, getreference restrictions in client script, it is allowed in OOB way.

 

Please mark helpful/correct if it added value.

In OOB it is possible to use GlideRecord but I have customization which restricts the usage of it.

I am getting the sys_id of the template applied in an alert. How can I query this to obtain the values in catalog client script. Is there any way to get the values here?