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

@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.

View solution in original post

3 REPLIES 3

Ankur Bawiskar
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.

Kasia5
Tera Contributor

Thank you!