Auto populate description field based on the value selected in a lookup select box type field in catalog item

SK41
Giga Guru

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.

 

1 ACCEPTED SOLUTION

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

9 REPLIES 9

In that case, you need to write a GlideAjax and script include to get those mapping from Server.

please refer:

https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/reference/r_ExamplesOfAsynchronousGlideAjax.html

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Which field in referred table contains description value and also in lookup select box, which field is selected as value field.

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

can  you  help  me  writing  the  script?

The field  called  devices  is  a  lookup  select  box  and  it  has  description (in  the  same table)for  each d evice against  it  in  the  table  called  hardware. When  user    select any  device  it  should  autopopulate  the  desciption field.

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

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Thanks!