Catalog Item Table Variable in Catalog Client Script

Jeff16
Tera Contributor

In a Catalog Client Script, how do I call table variables of that Catalog Item, specifically Model?

find_real_file.png

1 ACCEPTED SOLUTION

Chander Bhusha1
Tera Guru

Hi Jeff,

You can write a Glideajax in the onchange client script and get the model name from script include and use it in the script:

catalog client script:

var ga = new GlideAjax('catalogutilAjax'); //Script include name
ga.addParam('sysparm_name', 'getModelname'); //Method name 
ga.addParam('sysparm_item_sysid',g_form.getUniqueValue() ); //Current item sysid
ga.getXML(modelName);
 
function modelName(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  alert('Model name is = '+ answer); //This will be model name 

}

Script Include: catalogutilAjax  (Client callable - true)

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

	getModelname:function(){
		
		var itemsys  = this.getParameter('sysparm_item_sysid'); 
		var catGr = new GlideRecord('sc_cat_item'); //Checking in catalog item table
		if(catGr.get(itemsys)){
			return catGr.getDisplayValue('model'); //return model name
		}
	},
    type: 'catalogutilAjax'
});

 

The easiest way would be to create a string variable(make it hidden on the form) on catalog item and set the default value of that variable to the model of the catalog item and use that in the catalog client script

Default value : javascript:current.cat_item.model

Use that variable value in client script  using - g_form.getValue('new variable name');

 

 

View solution in original post

2 REPLIES 2

Chander Bhusha1
Tera Guru

Hi Jeff,

You can write a Glideajax in the onchange client script and get the model name from script include and use it in the script:

catalog client script:

var ga = new GlideAjax('catalogutilAjax'); //Script include name
ga.addParam('sysparm_name', 'getModelname'); //Method name 
ga.addParam('sysparm_item_sysid',g_form.getUniqueValue() ); //Current item sysid
ga.getXML(modelName);
 
function modelName(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  alert('Model name is = '+ answer); //This will be model name 

}

Script Include: catalogutilAjax  (Client callable - true)

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

	getModelname:function(){
		
		var itemsys  = this.getParameter('sysparm_item_sysid'); 
		var catGr = new GlideRecord('sc_cat_item'); //Checking in catalog item table
		if(catGr.get(itemsys)){
			return catGr.getDisplayValue('model'); //return model name
		}
	},
    type: 'catalogutilAjax'
});

 

The easiest way would be to create a string variable(make it hidden on the form) on catalog item and set the default value of that variable to the model of the catalog item and use that in the catalog client script

Default value : javascript:current.cat_item.model

Use that variable value in client script  using - g_form.getValue('new variable name');

 

 

Perfect!  Thank you!