- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 03:54 PM
In a Catalog Client Script, how do I call table variables of that Catalog Item, specifically Model?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 07:59 PM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 07:59 PM
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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 08:11 AM
Perfect! Thank you!