Assigned To feild should be greyed out if I am not member of the group

Sohini Kar
Tera Expert

Suppose I am part of Group A. I want to assign the incident to Group B.

If I am not part of Group B, then Assigned to feild should be greyed out. And I should not be allowed to assign it to any individual from Group B.

 

How can I achieve this?

3 REPLIES 3

NguyenN22513254
Tera Contributor

You can also use a UI Policy:

Condition: The user is not a member of the group
Action: Set the Assigned to field to read-only


Ankur Bawiskar
Tera Patron

@Sohini Kar 

so what did you start with and where are you stuck?

-> onChange of Group field do GlideAjax and check logged in user is member of that group and then make readonly

OR
-> onChange of Group field use GlideRecord with callback and check logged in user is member and then make readonly

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

    var group = newValue;
    var user = g_user.userID;

    // Helper: quickly check if user is in group
    var gr = new GlideRecord('sys_user_grmember');
    gr.addQuery('group', group);
    gr.addQuery('user', user);
    gr.query(checkRecord);
    function checkRecord(gr) {
        if (gr.hasNext()) {
            g_form.setReadOnly('assigned_to', false);
        } else {
            g_form.setReadOnly('assigned_to', true);
            g_form.clearValue('assigned_to'); // clear if needed
        }
    }
}

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Tanushree Maiti
Tera Sage
  1. Create New Display BR for the target table 
  2. Sample code (Advanced):

    g_scratchpad.mem = gs.getUser().isMemberOf('<sys_id of group B>');

  3. Create a client script (onload or Onchange) as per your requirement:

    Sample code:

    if(g_scratchpad.mem) 

    {
    g_form.setReadOnly('assifned_to',false);
    } else

    g_form.setReadOnly('assifned_to',true);}

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: