Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Force rank using choice list options - client script help needed

cynlink1
Tera Expert

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.

cynlink1_0-1701112006969.png

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);
    }
}

 

1 ACCEPTED SOLUTION

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');
}

View solution in original post

7 REPLIES 7

You're welcome! Thanks for catching that typo!

Cesar Avelar
Tera Contributor

Maybe You can try using a dependent value:

See this post 

Dependent choice 

Thank you for responding to my question. I ended up going with @KristenA1641094 's recommendation, but I appreciate the input.