Get Reference field values based on Choice field in catalog item
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 08:25 AM - edited ‎11-13-2022 08:41 AM
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'
};
Fields in groups table:
in catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 08:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 09:17 AM
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'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2022 09:24 AM
Hello,
Hope you made the script include client callable as below:-
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2022 06:30 AM
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'
});