Get Reference field values based on Choice field in catalog item

Vamshi Krishna2
Tera Contributor

Hi I have 2 variables LOB(Reference) and Domain(Select box) I'm trying to get the lob values based on the domain selected from groups table. but below script is showing blank output in the Reference variable.

Script Include:

Check: function(){
var Select_domain = current.variables.domain;
var lblist = new GlideRecord('sys_user_group');
lblist.addQuery('u_domain',Select_domain);
lblist.query();
var finalList = [];
while(lblist.next()){
finalList.push(lblist.getValue('sys_id'));
}
return 'sys_idIN' + finalList.join(',');

},
type: 'Populate_Groups'
};

VamshiKrishna2_0-1668356397671.png

Fields in groups table:

 

VamshiKrishna2_2-1668356585280.png

in catalog form

VamshiKrishna2_3-1668356646384.png

VamshiKrishna2_5-1668356722506.png

 

 

 

5 REPLIES 5

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

Two things you will have to make the script include client callable as true

 

Also just to be sure in the reference you are referencing to cmdb_ci_business_capability table but in script include you are using sys_user_group table and returning sys_id how would that work?

 

Please mark my answer as correct based on Impact.

sorry I forgot to update the lob backend value from group table but after updating still it is not working.

 

Yes I tried client callable script include which is not working still

Client Script:

var lb = g_form.getValue('domain');
var ajax = new GlideAjax('PopulateGroupName');
ajax.addParam('sysparm_name','getGroupNames');
ajax.addParam('sysparm_lob',lb);
ajax.getXML(getResponse);

function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

g_form.setValue('lob', answer);

}

Script include:

getGroupNames: function() {
//var names = '';
var arr = [];
var dom = this.getParameter('sysparm_lob');

if (dom == "secure") {
dom = "Secure";
}
else if (dom == 'i_com'){
dom = "I COM";
}
else if (dom == 'is_com'){
dom = "IS COM";
}
var gr = new GlideRecord('sys_user_group');
gr.addQuery('u_group_name',dom);
gr.query();
while (gr.next()) {
arr.push(gr.getValue('u_lob'));
}
return 'sys_idIN' + arr;
},
type: 'PopulateGroupName'

Hello,

 

Hope you made  the script include client callable as below:-

 

Saurav11_0-1668360120842.png

 

And I hope u_lob field is a reference field and contains the sysid's of the cmdb_ci_business_capability table

 

Please mark my answer as correct based on Impact.

 

 

Vamshi Krishna2
Tera Contributor

Yes it is client callable and updated but lob is showing all the records when I select Choice value

 

Client Script:

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

var lb = g_form.getValue('select_ad_domain');
var ajax = new GlideAjax('PopulateGroupName');
ajax.addParam('sysparm_name','getGroupNames');
ajax.addParam('sysparm_lob',lb);
ajax.getXML(getResponse);

function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");

g_form.setValue('lob', answer);

}
//Type appropriate comment here, and begin script below

}

 

Script include: 

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


getGroupNames: function() {
//var names = '';
var arr = [];
var dom = this.getParameter('sysparm_lob');
if (dom == "lc_aero") {
dom = "LC Aero";
}
else if (dom == 'yd_com'){
dom = "YD COM";
}
else if (dom == 'dc_com'){
dom = "DC COM";
}
else if (dom == 'hbsi_iad'){
dom = "HBSI IAD";
}
var gr = new GlideRecord('sys_user_group');
gr.addQuery('u_domain',dom);
gr.query();
while (gr.next()) {
arr.push(gr.getValue('u_lob'));
}
return 'u_lobIN' + arr;
},
type: 'PopulateGroupName'
});