- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi
I wish to control which choice options are displayed in a Variable based on the response of another variable. I have seen on the forums it is controlled by a On Change client script using addOption, or removeOption.
I have created the client script which works when the first variable value is changed, the second variable only displays the choice options I configured, however if the value of the first variable is changed again, the second variable choice options are incorrect, it does not refresh.
What am I missing in my script to ensure options are always updated based on variable 1 being changed. Here is my script
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
- fieldName: The exact backend column name of your choice list or select box.
- choiceValue: The actual value stored in the database when this option is selected.
- choiceLabel: The user-friendly text that appears inside the dropdown menu
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearOptions('which_role_s_do_you_require');
return;
}
if (newValue == 'Default') { // shows all choice options except the admin role 13587b75-c4d1-4a07-8641-9d00693b1f65
g_form.clearOptions('which_role_s_do_you_require');
g_form.addOption('which_role_s_do_you_require', '', '-- None --');
g_form.addOption('which_role_s_do_you_require', 'd74c4943-4347-4340-9a61-fc85ccce3ef7','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'a3f647e5-59b4-43c3-b05d-48ec2604d692','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '26687442-3860-419c-bc96-4069bcca3dc1','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '7de36bf0-828a-48a8-a31e-675f1e3983c7','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'e69af349-fb1b-4cf3-becd-d9e6a8ae8bd4','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'ae557f87-0a3d-47f0-91de-668de79e31e5','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'd5baf8dd-0fee-4d76-82c0-f884c198b4dd','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '43babf7d-6eb0-42e4-9dcd-95f19e93b922','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'd63088a0-335b-41ba-8450-bfd1c70ef85b','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '2d9202df-3977-493f-b354-ff9e05396583','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '5fbeb849-d34c-4a0b-9d28-fa23a2c41c57','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '82d368ef-bf79-4dd0-af2f-d8c68b2b1ff6','Label that need to be display');
}
if (newValue == 'Privileged') { // only displays the admin role 13587b75-c4d1-4a07-8641-9d00693b1f6
g_form.clearOptions('which_role_s_do_you_require');
g_form.addOption('which_role_s_do_you_require', '', '-- None --');
g_form.addOption('which_role_s_do_you_require', '13587b75-c4d1-4a07-8641-9d00693b1f65','Label that need to be display');
}
}Add the labels for all the above options.
If my response helped, mark it as helpful and accept the solution.
Thanks,
Dinesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
The main issue here is:
g_form.clearOptions();
clearOptions() requires the variable name as an argument. You need to clear the options specifically from which_role_s_do_you_require.
So the problem is not the overall approach. Change:
g_form.clearOptions();
to:
g_form.clearOptions('which_role_s_do_you_require');
and also add the g_form.clearOptions('which_role_s_do_you_require'); like below
if (isLoading || newValue == '') {
g_form.clearOptions('which_role_s_do_you_require');
return;
}
If my response helped, mark it as helpful and accept the solution.
Thanks,
Dinesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Thanks for the quick response, I updated the script with what you advised and now nothing happens, no choice options are displayed atall
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
- fieldName: The exact backend column name of your choice list or select box.
- choiceValue: The actual value stored in the database when this option is selected.
- choiceLabel: The user-friendly text that appears inside the dropdown menu
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
g_form.clearOptions('which_role_s_do_you_require');
return;
}
if (newValue == 'Default') { // shows all choice options except the admin role 13587b75-c4d1-4a07-8641-9d00693b1f65
g_form.clearOptions('which_role_s_do_you_require');
g_form.addOption('which_role_s_do_you_require', '', '-- None --');
g_form.addOption('which_role_s_do_you_require', 'd74c4943-4347-4340-9a61-fc85ccce3ef7','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'a3f647e5-59b4-43c3-b05d-48ec2604d692','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '26687442-3860-419c-bc96-4069bcca3dc1','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '7de36bf0-828a-48a8-a31e-675f1e3983c7','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'e69af349-fb1b-4cf3-becd-d9e6a8ae8bd4','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'ae557f87-0a3d-47f0-91de-668de79e31e5','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'd5baf8dd-0fee-4d76-82c0-f884c198b4dd','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '43babf7d-6eb0-42e4-9dcd-95f19e93b922','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', 'd63088a0-335b-41ba-8450-bfd1c70ef85b','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '2d9202df-3977-493f-b354-ff9e05396583','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '5fbeb849-d34c-4a0b-9d28-fa23a2c41c57','Label that need to be display');
g_form.addOption('which_role_s_do_you_require', '82d368ef-bf79-4dd0-af2f-d8c68b2b1ff6','Label that need to be display');
}
if (newValue == 'Privileged') { // only displays the admin role 13587b75-c4d1-4a07-8641-9d00693b1f6
g_form.clearOptions('which_role_s_do_you_require');
g_form.addOption('which_role_s_do_you_require', '', '-- None --');
g_form.addOption('which_role_s_do_you_require', '13587b75-c4d1-4a07-8641-9d00693b1f65','Label that need to be display');
}
}Add the labels for all the above options.
If my response helped, mark it as helpful and accept the solution.
Thanks,
Dinesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
46m ago
Hi Dinesh, that is brilliant, thankyou so much for the revision, it now works perfectly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @jonathangilbert
I just tried the below script in my PDI and it seems to working as per your requirement.
Give it a try and see..
function onChange(control, oldValue, newValue, isLoading) {
g_form.clearOptions('which_role_s_do_you_require');
if (isLoading || newValue == '') {
g_form.addOption('which_role_s_do_you_require', '', '-- None --');
return;
}
var roleMap = {
'Default': [
'13587b75-c4d1-4a07-8641-9d00693b1f65'
],
'Privileged': [
'd74c4943-4347-4340-9a61-fc85ccce3ef7',
'a3f647e5-59b4-43c3-b05d-48ec2604d692',
'26687442-3860-419c-bc96-4069bcca3dc1',
'7de36bf0-828a-48a8-a31e-675f1e3983c7',
'e69af349-fb1b-4cf3-becd-d9e6a8ae8bd4',
'ae557f87-0a3d-47f0-91de-668de79e31e5',
'd5baf8dd-0fee-4d76-82c0-f884c198b4dd',
'43babf7d-6eb0-42e4-9dcd-95f19e93b922',
'd63088a0-335b-41ba-8450-bfd1c70ef85b',
'2d9202df-3977-493f-b354-ff9e05396583',
'5fbeb849-d34c-4a0b-9d28-fa23a2c41c57',
'82d368ef-bf79-4dd0-af2f-d8c68b2b1ff6'
]
};
var roles = roleMap[newValue];
if (roles && roles.length > 0) {
g_form.addOption('which_role_s_do_you_require', '', '-- None --');
for (var i = 0; i < roles.length; i++) {
g_form.addOption('which_role_s_do_you_require', roles[i], roles[i]);
}
}
}
Regards,
Siva