- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 07:47 AM
Hi,
I have to auto populate description field based on the value selected in a lookup select box type field which is referring a table in a catalog item. How can i achieve that through scripting?
Kindly, help me in this regard.
Thanks.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 10:27 PM
client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax("HardwareDescription");
ga.addParam("sysparm_name","getDescription");
ga.addParam("sysparm_id",newValue);
ga.getXML(callBackFun);
function callBackFun(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer){
g_form.setValue("description", answer);
}
}
}
Script include:
Name: HardwareDescription
Client callable: true
script:
var HardwareDescription = Class.create();
HardwareDescription.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDescription: function(){
var id = this.getParameter("sysparm_id");
var grh = new GlideRecord("alm_hardware");
grh.addQuery("sys_id",id);
grh.query();
if(grh.next()){
return grh.getValue("description") + "";
}
return "";
},
type: 'HardwareDescription'
});
Please note:
1. Verify all field back end names and table names.
2. In lookup select back, verify if Value field is set as sys_id
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 07:56 AM
'onChange' Catalog Client Script, variable name {your lookup select box}
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var c_field = g_form.getReference('your_field', setF); //your custom field+callback function }
function setF(your_field) {
g_form.setValue('description',your_field.reference_field);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 09:29 PM
This does not work for lookup select box field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 09:37 PM
How many options you have in lookup select box?
if number of options are less, then you can try below script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Repeat below condition for number of options in elect box
if(newValue == "option1 in select box field"){
g_form.setValue("description_field_name","description value you want to set");
}
}
If number of options are more or dynamic, you need to have a place (some property or a table) where you have mapping between option value and description value.
Then in onchange script, read that mapping and based on current option, you can set description.
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-22-2020 09:43 PM
This lookup select box is referring a table that has mapping in it for many records.
This static script will not work.