
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 11:19 AM
Hello,
My requirement is as follows:
Require user to rank the Avoid, Mitigate, Transfer and Accept fields using choice list options: highest, second highest, second lowest, lowest. The problem I am encountering is how to best prohibit the user from using the choice list options more than once.
I began working on a client script and was able to limit the choices in the Mitigate field based on the choice selected in the Highest field. However, I am struggling with the complexity of applying the logic to all the other fields. Is there an easier way to approach this task?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.clearOptions('u_business_disruption_mi');
g_form.clearOptions('u_business_disruption_tr');
g_form.clearOptions('u_business_disruption_ac');
if (newValue == 4) {
//Mitigate
g_form.addOption('u_business_disruption_mi', '', '-- None --', 1);
g_form.addOption('u_business_disruption_mi', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_mi', '2', 'Second Lowest', 300);
g_form.addOption('u_business_disruption_mi', '1', 'Lowest', 400);
//Transfer
g_form.addOption('u_business_disruption_tr', '', '-- None --', 1);
g_form.addOption('u_business_disruption_tr', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_tr', '2', 'Second Lowest', 300);
g_form.addOption('u_business_disruption_tr', '1', 'Lowest', 400);
//Accept
g_form.addOption('u_business_disruption_ac', '', '-- None --', 1);
g_form.addOption('u_business_disruption_ac', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_ac', '2', 'Second Lowest', 300);
g_form.addOption('u_business_disruption_ac', '1', 'Lowest', 400);
}
if (newValue == 3) {
//Mitigate
g_form.addOption('u_business_disruption_mi', '', '-- None --', 1);
g_form.addOption('u_business_disruption_mi', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_mi', '2', 'Second Lowest', 300);
g_form.addOption('u_business_disruption_mi', '1', 'Lowest', 400);
//Transfer
g_form.addOption('u_business_disruption_tr', '', '-- None --', 1);
g_form.addOption('u_business_disruption_tr', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_tr', '2', 'Second Lowest', 300);
g_form.addOption('u_business_disruption_tr', '1', 'Lowest', 400);
//Accept
g_form.addOption('u_business_disruption_ac', '', '-- None --', 1);
g_form.addOption('u_business_disruption_ac', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_ac', '2', 'Second Lowest', 300);
g_form.addOption('u_business_disruption_ac', '1', 'Lowest', 400);
}
if (newValue == 2) {
//Mitigate
g_form.addOption('u_business_disruption_mi', '', '-- None --', 1);
g_form.addOption('u_business_disruption_mi', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_mi', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_mi', '1', 'Lowest', 400);
//Transfer
g_form.addOption('u_business_disruption_tr', '', '-- None --', 1);
g_form.addOption('u_business_disruption_tr', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_tr', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_tr', '1', 'Lowest', 400);
//Accept
g_form.addOption('u_business_disruption_ac', '', '-- None --', 1);
g_form.addOption('u_business_disruption_ac', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_ac', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_ac', '1', 'Lowest', 400);
}
if (newValue == 1) {
//Mitigate
g_form.addOption('u_business_disruption_mi', '', '-- None --', 1);
g_form.addOption('u_business_disruption_mi', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_mi', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_mi', '2', 'Second Lowest', 300);
//Transfer
g_form.addOption('u_business_disruption_tr', '', '-- None --', 1);
g_form.addOption('u_business_disruption_tr', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_tr', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_tr', '2', 'Second Lowest', 300);
//Accept
g_form.addOption('u_business_disruption_ac', '', '-- None --', 1);
g_form.addOption('u_business_disruption_ac', '4', 'Highest', 100);
g_form.addOption('u_business_disruption_ac', '3', 'Second Highest', 200);
g_form.addOption('u_business_disruption_ac', '2', 'Second Lowest', 300);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 11:58 AM
I would still use an onChange client script, but I would do something like:
var avoidMatch = newValue == g_form.getValue('avoid');
var transferMatch = newValue == g_form.getValue('transfer');
var acceptMatch = newValue == g_form.getValue('accept);
if(avoidMatch || transferMatch || acceptMatch){
g_form.clearValue('mitigate');
g_form.showFieldMessage('mitigate','You cannot select the same option twice.','error');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 11:31 AM
Do you have to change the actual choices? If not, then the simplest solution would be to validate the new option to all the other fields and reject the choice when it duplicates another. In this solution, they would always see all the options, but if they choose "Highest" on "Avoid" and then try to select "Highest" on "Mitigate", it would change "Mitigate" back to --None-- and show a field message that they cannot reuse rankings.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 11:40 AM
Changing the actual choices is desired by the client. However, if I can demonstrate a working alternative, they will likely accept it. When you refer to 'validate' the new option, are you referring to using another script or leveraging OOTB functionality?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 11:58 AM
I would still use an onChange client script, but I would do something like:
var avoidMatch = newValue == g_form.getValue('avoid');
var transferMatch = newValue == g_form.getValue('transfer');
var acceptMatch = newValue == g_form.getValue('accept);
if(avoidMatch || transferMatch || acceptMatch){
g_form.clearValue('mitigate');
g_form.showFieldMessage('mitigate','You cannot select the same option twice.','error');
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2023 02:03 PM
It worked after I updated showFieldMessage to showFieldMsg. Thank you for the assistance!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Business Disruption TRANSFER
//Enforce unique choice list value for u_business_disruption_tr
var match1 = newValue == g_form.getValue('u_business_disruption_ac');
var match2 = newValue == g_form.getValue('u_business_disruption_av');
var match3 = newValue == g_form.getValue('u_business_disruption_mi');
if (match1 || match2 || match3) {
g_form.clearValue('u_business_disruption_tr');
g_form.showFieldMsg('u_business_disruption_tr', 'You cannot select the same option twice.', 'error');
}
}