Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Hi @Rahul Raja Sami 

It's clearValue, it's not used to remove options. 

I was intended to set the On Hold Reason back to None when the Category is changes to empty. You can remove that line.

 

Cheers,

Tai Vu

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Rahul Raja Sami 

 

Follow the same way as followed in Incident

 

LearnNGrowAtul_0-1701360073242.png

 

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Amit Gujarathi
Giga Sage
Giga Sage

HI @Rahul Raja Sami ,
I trust youa re doing great.
Please find the below reference script :

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue === '') {
        return;
    }

    var reasonField = g_form.getField('on_hold_reason'); // Replace with actual field name
    var facilitiesCategoryValue = 'facilities'; // Replace with the actual value for the facilities category

    // Check if the category is 'facilities'
    if (newValue == facilitiesCategoryValue) {
        // Show the options
        reasonField.enableOption('awaiting delivery');
        reasonField.enableOption('awaiting payment');
        reasonField.enableOption('awaiting contractor');
    } else {
        // Hide the options
        reasonField.disableOption('awaiting delivery');
        reasonField.disableOption('awaiting payment');
        reasonField.disableOption('awaiting contractor');
    }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi