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

sachinbhasin11
Tera Guru
Tera Guru

Hi Sawrna,

 

You can try roles instead, check the below link

 

https://community.servicenow.com/community?id=community_question&sys_id=2485c64cdb25ef04107d5583ca96...

 

Please mark helpful if it helps !

Community Alums
Not applicable

Hi Swarna,

 

if you just want to add a category, you can use the following scripts:

Step 1: Create a display Business rule with script as. Place the below script between function templates in script body.

g_scratchpad.group_name= gs.getUser().isMemberOf('PASS GROUP NAME HERE');  

 

Step 2: Create on load client script as such:

function onLoad() {
if(g_scratchpad.group_name)
{
g_form.addOption('field name', 'your_option_value', 'Your Option Label');
}
}

 

Please mark as helpful/correct if this helps! 🙂

Thanks

DR

Thanks Debopriya.

But the field Incident closure category type is dependent on  Incident closure category.

If we do add option here in thsi case, it isn't working. Did you test this code in your personal instance? I guess it won't work.

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