want to make some on hold choices visible for particular category

Rahul Raja Sami
Tera Guru

Hi I have added new choices for On Hold Reason 
1. awaiting delivery
2. awaiting payment

3. awaiting contractor 
and I want them to be visible only when the category is facilities and should be hidden for other categories.

Thanks.

1 ACCEPTED SOLUTION

I was able to achieve this on my PDI for both scenarios.

 

1. Wrote down a onChange client script on Category field & put following code into it

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue === '') {
        return;
    }
    if (isLoading && oldValue != 'inquiry') { ///update with backend value of Facilities choice here
        g_form.removeOption('hold_reason', '1'); //update with backend value of choices which you don't want to see on other categories
        g_form.removeOption('hold_reason', '5');
        return;
    }

    if (newValue === 'inquiry') { //update with backend value of Facilities choice here
        g_form.addOption('hold_reason', '1', 'Awaiting Caller'); //update the backend & front-end labels here which you only want to see in facilities category
        g_form.addOption('hold_reason', '5', 'Awaiting Change');
        return;
    }

    g_form.removeOption('hold_reason', '1');
    g_form.removeOption('hold_reason', '5');

}

 

2. Do make sure you update the backend values & front-end values of the choices.

 

3. In my scenario, I am hiding choices on all other categories apart from 'Inquiry' category. It should work.

 

3.1 Hide on all other categories.png

 

3.2 Show only on Inquiry.png

 

Do mark this response as CORRECT / HELPFUL as it will help others & will motivate me as well to write more.

View solution in original post

12 REPLIES 12

I was able to achieve this on my PDI for both scenarios.

 

1. Wrote down a onChange client script on Category field & put following code into it

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue === '') {
        return;
    }
    if (isLoading && oldValue != 'inquiry') { ///update with backend value of Facilities choice here
        g_form.removeOption('hold_reason', '1'); //update with backend value of choices which you don't want to see on other categories
        g_form.removeOption('hold_reason', '5');
        return;
    }

    if (newValue === 'inquiry') { //update with backend value of Facilities choice here
        g_form.addOption('hold_reason', '1', 'Awaiting Caller'); //update the backend & front-end labels here which you only want to see in facilities category
        g_form.addOption('hold_reason', '5', 'Awaiting Change');
        return;
    }

    g_form.removeOption('hold_reason', '1');
    g_form.removeOption('hold_reason', '5');

}

 

2. Do make sure you update the backend values & front-end values of the choices.

 

3. In my scenario, I am hiding choices on all other categories apart from 'Inquiry' category. It should work.

 

3.1 Hide on all other categories.png

 

3.2 Show only on Inquiry.png

 

Do mark this response as CORRECT / HELPFUL as it will help others & will motivate me as well to write more.

It is working and is there a chance to set their sequence as well?

g_form.addOption('field'_name, '1', 'Awaiting Info', 1); //add the order in the last parameter like 1,2,3,4 while adding these
g_form.addOption('field_name', '5, 'Awaiting Change', 2); //add number at the end at whatever position you want to add these.

 

Mark this response as CORRECT if it completes your requirement. Will help others & definitely motivate me to write more.

 

Tai Vu
Kilo Patron
Kilo Patron

Hi @Rahul Raja Sami 

You can define an OnChange Client Script on the Category field, in order to manage both when the form load and when the Category changes.

UI Type: All

Type: OnChange

Field: Category

Sample script

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (newValue === 'facilities') {
        g_form.addOption('hold_reason', 'Awating Delivery', 'awaiting delivery');
        g_form.addOption('hold_reason', 'Awating Delivery', 'awaiting payment');
        g_form.addOption('hold_reason', 'Awating Delivery', 'awaiting contractor');
        return;
    }

    g_form.clearValue('hold_reason');
    g_form.removeOption('hold_reason', 'awaiting delivery');
    g_form.removeOption('hold_reason', 'awaiting payment');
    g_form.removeOption('hold_reason', 'awaiting contractor');

}

 

 

If the On Hold Reason field is not always visible and depends on the State field, you may also need to consider to have another OnChange Client Script on the State field as well.

 

Cheers,

Tai Vu 

if we use clearoption will not be cleared all the other options as well? timi