- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2020 11:24 AM
I have an onChange client script that collects an array of values (groups) that the user selected is in. How can I add these values in a select box as options?
I want those values in the "Existing HLA Access in Group(s):" field to be options in remove from group. For example: "Domain RTR Admins", "Domain CyberArk Users", and "Domain SMS Users-WAN" as options in the "Remove from Group" Select Box. The text in that field will change whenever the requested for is changed, so I need to create a functionality that will populate the selectbox options with that.
Here is the client script to populate the first text field:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getHLAGroups');
ga.addParam('sysparm_name', 'groupHLA');
ga.addParam('sysparm_userSelect', g_form.getValue('u_user_hla'));
ga.getXML(updateGroup);
}
function updateGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert('Answer is: '+answer);
answer = answer.slice(0, -1);
var inAnswer = answer.split(';');
var outData = '';
for (var i=0; i < inAnswer.length; i++) {
outData = outData+'\n'+inAnswer[i].toString();
}
g_form.setValue('u_group_hla', outData);
}
I tried this:
myArray = answer.split(",");
var a = myArray[0];
alert(a);
g_form.addOption('remove_from_group', 'myArray[0]','myArray');
but it keeps adding "MyArray" as the only option in the select box.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2020 11:28 AM
try below
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('getHLAGroups');
ga.addParam('sysparm_name', 'groupHLA');
ga.addParam('sysparm_userSelect', g_form.getValue('u_user_hla'));
ga.getXML(updateGroup);
}
function updateGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert('Answer is: '+answer);
answer = answer.slice(0, -1);
var inAnswer = answer.split(';');
var outData = '';
for (var i = 0; i < inAnswer.length; i++) {
outData = outData + '\n' + inAnswer[i].toString();
g_form.addOption('u_group_hla', inAnswer[i].toString(), inAnswer[i].toString());
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 08:05 AM
Yes correct,
Both the fields are Lookup select box
1) BU
2) Country
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2023 09:18 AM
Can you also give a sample of your referenced table, so I can try to recreate what you are attempting to do? I think you should be able to use the ref_qual_elements attribute to do this, and not have to use a client script.
Variable Attributes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2020 02:02 PM
The reason "MyArray" kept displaying, is due to quotes around the myArray[0] (value) and myArray (label) in your g_form. You set the value and label to a string value and not the variable value. When you use the g_form.addOption method, the only way to make it change each time is to clear the options prior to rebuilding them based on the variable value.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Clear any options in the variable everytime the script runs
g_form.clearOptions('u_group_hla');
var ga = new GlideAjax('getHLAGroups');
ga.addParam('sysparm_name', 'groupHLA');
ga.addParam('sysparm_userSelect', g_form.getValue('u_user_hla'));
ga.getXML(updateGroup);
}
function updateGroup(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
// alert('Answer is: '+answer);
answer = answer.slice(0, -1);
var inAnswer = answer.split(';');
var outData = '';
for (var i = 0; i < inAnswer.length; i++) {
outData = outData + '\n' + inAnswer[i].toString();
g_form.addOption('u_group_hla', inAnswer[i].toString(), inAnswer[i].toString());
}
}
