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.

How to remove or disable an option for a field dependent on another field for a certain group?

Swarnarghya Gho
Giga Contributor

How to remove or disable an option for  a field dependent on another field for a certain group?

In the incident field, there are three fields: Incident closure category, Incident closure category type and incident closure category item.

Incident closure category type is dependent on Incident closure category.
I need to add an option for  Incident closure category and that option will be available for one particular group.

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi Swarna,

 

I tried this on my OOB instance, Subcategory field for Incident table, that field is dependent on Category field.

find_real_file.png

 

If you want to add some options for Incident closure category, would that mean it will have its particular set of category type too? 

Here  I have created a Category,and 2 dependent subcategory and the following script displays the category only for members of particular group when a new record is being created:

find_real_file.png

find_real_file.png

 

function onLoad() {
//Type appropriate comment here, and begin script below
if(g_form.isNewRecord()) //to stop value from changing once the form has submitted.
{
g_form.removeOption('category','test_cat');
if(g_scratchpad.group_name) //from previous display BR
{
g_form.addOption('category', 'test_cat','Test Cat');
}
}
}

 

Please mark as correct/helpful if this helps! 🙂

Thanks

DR

View solution in original post

6 REPLIES 6

If you want to add some options for Incident closure category, would that mean it will have its particular set of category type too? --> Yes that's true.

I have incident category options as - Test 1, test2 and test 3 and incident category have 9 options: test 4, test 5,....,test9. Now test 4 and test 5 is dependent on test 1, test 6 and test 7 is dependent on test 2 and likewise.

Your script is write but it is not matching my requirement.

My req. is i need to add another option say for ex: test 50 which must be dependent on test 1 and it should be visible only to the members of a particular group say: Server group.

Correction in second paragraph: I have incident category options as - Test 1, test2 and test 3 and incident category type  have 9 options: test 4, test 5,....,test9. Now test 4 and test 5 is dependent on test 1, test 6 and test 7 is dependent on test 2 and likewise