Hide options frm Urgency field in INC form when logged in user is in group which name starts with AB

Kasia5
Tera Contributor

Hi All

 

I need to create Client Script to check if logged in user is in group which name starts with 'AB'. If yes then remove two options from Urgency field in Incident form: 1- High and 2 - Medium

 

How can I create the script?

 

Thanks in advance

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Kasia5 

You can use combination of display business rule + onload client script

Business rule:

(function executeRule(current, previous /*null when async*/ ) {

    // Query the sys_user_grmember table to get the groups of the logged-in user
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', gs.getUserID());
    gr.addQuery('group.name', 'STARTSWITH', 'AB');
    gr.setLimit(1);
    gr.query();
    g_scratchpad.userGroups = gr.hasNext().toString();

})(current, previous);

onLoad client script:

function onLoad() {
    var isMember = g_scratchpad.userGroups;
    // If the user is in an 'AB' group, remove 'High' and 'Medium' options from the Urgency field
    if (isMember.toString() == 'true') {
        g_form.removeOption('urgency', '1'); // High
        g_form.removeOption('urgency', '2'); // Medium
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Kasia5 

 

https://www.servicenow.com/community/developer-forum/how-do-i-hide-a-category-an-incident-form-if-us...

 

https://www.servicenow.com/community/itsm-forum/to-hide-remove-some-of-the-categories-and-some-of-th...

 

*************************************************************************************************************
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]

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

Ankur Bawiskar
Tera Patron
Tera Patron

@Kasia5 

You can use combination of display business rule + onload client script

Business rule:

(function executeRule(current, previous /*null when async*/ ) {

    // Query the sys_user_grmember table to get the groups of the logged-in user
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('user', gs.getUserID());
    gr.addQuery('group.name', 'STARTSWITH', 'AB');
    gr.setLimit(1);
    gr.query();
    g_scratchpad.userGroups = gr.hasNext().toString();

})(current, previous);

onLoad client script:

function onLoad() {
    var isMember = g_scratchpad.userGroups;
    // If the user is in an 'AB' group, remove 'High' and 'Medium' options from the Urgency field
    if (isMember.toString() == 'true') {
        g_form.removeOption('urgency', '1'); // High
        g_form.removeOption('urgency', '2'); // Medium
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Kasia5
Tera Contributor

Thank you!