Populating the choices for a list collector variable based on a select box and a list collector
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Wednesday
Hello Everyone
I need help in populating the values in a list collector variable "Groups" on the question_choice table.
In the catalog form, I have a select box called "Roles" with values "Ädmin" and "User".
The first list collector variable "Ënv" is also on the question choice table with values like DEV, PROD, UAT.
When I select role as "admin" and env as "DEV", the Group list collector should display values pertaining to only admin-dev.
I have added the variable attributes in the "Groups" variable as ref_qual_elements=roles,env.
I have an Onchange client script on the "Env" list collector variable as below:
// Client Script: Handle Field Change
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
// Initialize GlideAjax and point it to the Script Include name
var ga = new GlideAjax('ChoiceFilterUtil');
// Specify the function name within the Script Include
ga.addParam('sysparm_name', 'getFilteredChoices');
// Pass a parameter to the server
ga.addParam('sysparm_field_value2', newValue);
ga.addParam('sysparm_field_value1', g_form.getValue('roles'));
// Send the request to the server
ga.getXML(ajaxResponse);
// Callback function processes the server response
function ajaxResponse(response) {
var answer = response.responseText;
var answerObj = JSON.parse(answer); // Parse the JSON response
if (answerObj.success) {
alert(answerObj.message);
// You can also set other form fields here:
g_form.setValue('groups', 'answerObj.message');
} else {
alert(answerObj.message);
}
}
}
====================================================================
My Script include is
var ChoiceFilterUtil = Class.create();
ChoiceFilterUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFilteredChoices: function() {
var role = this.getParameter('sysparm_field_value1');
var env = this.getParameter('sysparm_field_value2');
var groupSysIds = [];
// Add condition based on the Select Box value
if (role == 'admin' && env == '78b608f1831676101997b8a6feaad3a1'){
gs.addInfoMessage("Ïnside first if");
// Adjust this condition based on how your select box choices relate to the second list collector choices
groupSysIds.push("86e7cc75831676101997b8a6feaad352");
}
if (role === 'admin' && env === '38070435831676101997b8a6feaad3d3') {
// Adjust this condition based on how your select box choices relate to the second list collector choices
groupSysIds.push("e0484cb5831676101997b8a6feaad3f3");
}
// Return the final encoded query
gs.addInfoMessage("Groupsysid in line 52 is " +JSON.stringify(groupSysIds));
return groupSysIds.join(',');
//return filterQuery;
//return JSON.stringify(groupSysIds);
},
type: 'ChoiceFilterUtil'
});
====================================================================================
The issue is when i select both dev and uat from the "Env" list collector it returns null .
Groupsysid in line 52 is []
Can someone please help me with the script that the "Groups" sys ids should be passed properly to the client script and set in the list collector variable.
Thanks in Advance.
0 REPLIES 0
