Hiding Choice Options

jonathangilbert
Mega Sage

Hi All

 

I have used a Onload client script before to hide "choice" options based on the value of another field, but for some reason I cannot get it to work. The Script is set on the task table as I want it to operate on both Incidents and RITMS.

 

Our scenerio is we have a field called "Attempted Contact " (u_attempted_contact), which has the following choice options :- 

First Attempt

Second Attempt

Third Attempt

Escalated to Regional Coach

 

We would like to only make the next option in the sequence visble to select, so if you had chosen "First Attempt" and ave the record, if you went back to that field, then the only option to select this time would be "Second Attempt" and so On.

 

To partially achieve this I have created another field called "Attempted Contact (Current Value)", which stores the value of the "Attempted Contact" after that field has been changed. That way my client script could look up the value of this field and then remove the appropiate options from the "Attempted Contact" field

 

So an example below, I selected "First Attempt" and save the record, so then "Attempted Contact "Current Value) got auto populated

First Attempt Screenshot.png

 

What I then want to happen is if i then wanted to change the value of the "Attempted Contact" again then it shoudl only display "Second Attempt" as a choice, but it doesn't it displays this:-

options presented.png

 

Here is my script

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   var ticketType = g_form.getValue("u_attempted_contact_current_value");
   if (ticketType == "First Attempt") {
    g_form.removeOption('u_attempted_contact', 'First Attempt');
    g_form.removeOption('u_attempted_contact', 'Third Attempt');
    g_form.removeOption('u_attempted_contact', 'Escalated to Regional Coach');
   }
 
}
 
 
 
What am I missing?
Thanks in advance
3 REPLIES 3

Brad Bowman
Kilo Patron
Kilo Patron

Make sure you are using the choice values in the script, not the Label - for both fields.  Add an alert to the script if in doubt.  For example, in the out of box Category field, you would use 'inquiry' not 'Inquiry / Help'.

BradBowman_0-1766417759282.png

 

Anand2799
Tera Guru

Hi @jonathangilbert ,

 

Verify you are using internal value of choice field.

 

Thanks

Anand

M Iftikhar
Tera Sage

Hi @jonathangilbert,
It can be achieved by restricting the options only after the first selection.

On the first load, when no value has been selected yet, all choices remain visible. Once a value is selected and saved, the onLoad client script clears the choices and displays only the next valid option in the sequence.

function onLoad() {
    var currentValue = g_form.getValue('u_attempted_contact_current_value');

    // First time / no previous selection → show all options
    if (!currentValue) {
        return;
    }

    // Restrict options only after a value exists
    g_form.clearOptions('u_attempted_contact');

    if (currentValue == 'first_attempt') {
        g_form.addOption('u_attempted_contact', 'second_attempt', 'Second Attempt');
    }
    else if (currentValue == 'second_attempt') {
        g_form.addOption('u_attempted_contact', 'third_attempt', 'Third Attempt');
    }
    else if (currentValue == 'third_attempt') {
        g_form.addOption('u_attempted_contact', 'escalated', 'Escalated to Regional Coach');
    }
}


If my response helped, please mark it as the accepted solution so others can benefit as well. 

Thanks & Regards,
Muhammad Iftikhar

If my response helped, please mark it as the accepted solution so others can benefit as well.