- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 08:10 AM
Hello All,
I'm trying to populate a selectbox variable based on a single line text field. As we can see in the below image, I'm trying to autopopulate dropdown choice based on a single line text field value. As you can see in the below image, but below script, it's not working as expected. Can someone help me with corrections to the script?
LAN ID == Single line Text variable
Domain == Dropdown/selectbo
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var lanId = g_form.getValue('lan_id');
lanId = ["ACCPT", "AF", "AP", "EA", "NA", "SA", "UPSTREAMACCTS"];
if (lanId.indexOf('ACCPT') !== -1) {
g_form.setValue('domain', 'ACCPT');
} else if (lanId.indexOf('AF') !== -1) {
g_form.setValue('domain', 'AF');
} else if (lanId.indexOf('AP') !== -1) {
g_form.setValue('domain', 'AP');
} else if (lanId.indexOf('EA') !== -1) {
g_form.setValue('domain', 'EA');
} else if (lanId.indexOf('NA') !== -1) {
g_form.setValue('domain', 'NA');
} else if (lanId.indexOf('SA') !== -1) {
g_form.setValue('domain', 'SA');
} else if (lanId.indexOf('UPSTREAMACCTS') !== -1) {
g_form.setValue('domain', 'UPSTREAMACCTS');
}
}
Thanks,
JRY
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 08:21 AM - edited 10-25-2022 08:23 AM
Hi @JRY
Can you try this:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var lanId = g_form.getValue('lan_id');
//lanId = ["ACCPT", "AF", "AP", "EA", "NA", "SA", "UPSTREAMACCTS"]; //commented this line
if (lanId.indexOf('ACCPT') >-1) {
g_form.setValue('domain', 'ACCPT');
} else if (lanId.indexOf('AF') >-1) {
g_form.setValue('domain', 'AF');
} else if (lanId.indexOf('AP') >-1) {
g_form.setValue('domain', 'AP');
} else if (lanId.indexOf('EA')>-1) {
g_form.setValue('domain', 'EA');
} else if (lanId.indexOf('NA') >-1) {
g_form.setValue('domain', 'NA');
} else if (lanId.indexOf('SA') >-1) {
g_form.setValue('domain', 'SA');
} else if (lanId.indexOf('UPSTREAMACCTS') >-1) {
g_form.setValue('domain', 'UPSTREAMACCTS');
}
}
Hope it works
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 01:00 AM
Hi Murthy,
I have tried your script as you can see in below image it's taking wrong choice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 01:24 AM
Hi @JRY
Yes it's because it is satisfying the below else if condition before going to the last else if
else if (lanId.indexOf('EA')>-1) {
g_form.setValue('domain', 'EA');
As your text contains the EA in the LAN ID the EA option is populated.
So you just need to update the condition in the else if where it has to be unique in the indexOf
Hope it helps..
Note: No issues in the logic.
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 02:12 AM
Thanks, I have modified the value now it's working fine.
Thanks,
JRY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2022 08:42 AM
Hello,
Are you trying to set a single value or a choice of values in the dropdown:-
If it is a choice of value add all the options at top i.e by using :-
g_form.addOption('domain','ACCPT','ACCPT',1); // do it for all options
and then in the if statement just remove the option using:-
g_form.removeOption('domain','ACCPT');
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-26-2022 12:47 AM
Hi Saurav,
I tried the below script as you suggested, but it didn't work. capturing the wrong value. Can you please tell me what went wrong with the below script?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.addOption('domain', 'ACCPT', 'ACCPT', 1);
g_form.addOption('domain', 'AF', 'AF', 2);
g_form.addOption('domain', 'AP', 'AP', 3);
g_form.addOption('domain', 'EA', 'EA', 4);
g_form.addOption('domain', 'NA', 'NA', 5);
g_form.addOption('domain', 'SA', 'SA', 6);
g_form.addOption('domain', 'UPSTREAMACCTS', 'UPSTREAMACCTS', 7);
return;
}
var lanId = g_form.getValue('lan_id');
lanId = ["ACCPT", "AF", "AP", "EA", "NA", "SA", "UPSTREAMACCTS"];
if (lanId.indexOf('ACCPT')) {
g_form.addOption('domain', 'ACCPT', 'ACCPT');
g_form.removeOption('domain', 'AF');
g_form.removeOption('domain', 'AP');
g_form.removeOption('domain', 'EA');
g_form.removeOption('domain', 'NA');
g_form.removeOption('domain', 'SA');
g_form.removeOption('domain', 'UPSTREAMACCTS');
} else if (lanId.indexOf('AF')) {
g_form.addOption('domain', 'AF', 'AF');
g_form.removeOption('domain', 'ACCPT');
g_form.removeOption('domain', 'AP');
g_form.removeOption('domain', 'EA');
g_form.removeOption('domain', 'NA');
g_form.removeOption('domain', 'SA');
g_form.removeOption('domain', 'UPSTREAMACCTS');
} else if (lanId.indexOf('AP')) {
g_form.addOption('domain', 3, 'AP');
g_form.removeOption('domain', 'ACCPT');
g_form.removeOption('domain', 'AF');
g_form.removeOption('domain', 'EA');
g_form.removeOption('domain', 'NA');
g_form.removeOption('domain', 'SA');
g_form.removeOption('domain', 'UPSTREAMACCTS');
} else if (lanId.indexOf('EA')) {
g_form.addOption('domain', 'EA', 'EA');
g_form.removeOption('domain', 'ACCPT');
g_form.removeOption('domain', 'AF');
g_form.removeOption('domain', 'AP');
g_form.removeOption('domain', 'NA');
g_form.removeOption('domain', 'SA');
g_form.removeOption('domain', 'UPSTREAMACCTS');
} else if (lanId.indexOf('NA')) {
g_form.addOption('domain', 'NA', 'NA');
g_form.removeOption('domain', 'ACCPT');
g_form.removeOption('domain', 'AF');
g_form.removeOption('domain', 'AP');
g_form.removeOption('domain', 'EA');
g_form.removeOption('domain', 'SA');
g_form.removeOption('domain', 'UPSTREAMACCTS');
} else if (lanId.indexOf('SA')) {
g_form.addOption('domain', 'SA', 'SA');
g_form.removeOption('domain', 'ACCPT');
g_form.removeOption('domain', 'AF');
g_form.removeOption('domain', 'AP');
g_form.removeOption('domain', 'NA');
g_form.removeOption('domain', 'EA');
g_form.removeOption('domain', 'UPSTREAMACCTS');
} else if (lanId.indexOf('UPSTREAMACCTS')) {
g_form.addOption('domain', 'UPSTREAMACCTS', 'UPSTREAMACCTS');
g_form.removeOption('domain', 'ACCPT');
g_form.removeOption('domain', 'AF');
g_form.removeOption('domain', 'AP');
g_form.removeOption('domain', 'NA');
g_form.removeOption('domain', 'SA');
g_form.removeOption('domain', 'EA');
}
}