business rule to see if users group is in list

James Roberts
Giga Contributor

Hi all

I need a bit of help with finding if a users group is in a watch list.

I have all the service portal side working and business rule to assign the correct group to the custom watch list for an instance but where in stuck is modifying the base incident query.

 

Currently I have it working when looking for a specific group ID but i need to get the current users groups and check them against the custom "u_manager_visibility_list" watch list. This watch list currently only contains 1 group at any one time.

restrictIncidents();

	function restrictIncidents() {
   if (!gs.hasRole("itil") && gs.isInteractive()) {
        // PRB1314624: Do NOT restrict Incidents if SPM plugin is active AND user has the service_viewer role.
        if (GlidePluginManager.isActive('com.snc.spm') && gs.hasRole('service_viewer'))
            return;

	var sgroup = "6072b43ddb73b300d50d80e2399619c9";
        var u = gs.getUserID();
        var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition("u_manager_visibility_list", "CONTAINS", sgroup);
        gs.print("query restricted to user: " + u);
    }
	}

 

sgroup needs to be dynamic and be the current users group(s). Also as a user may have multiple i need it to be able to handle this. the only groups we want to check will have a format of "_All *variable name* Managers" (so they all begin with _All and end with Managers). Again a user may be in multiple managers groups.

 

I'm struggling to figure out the best way to approach this as i'm still fairly new to all this.

 

Thanks in advance

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi James,

So update code as below and check once; it should work

var sgroup = gs.getUser().getMyGroups(); // get the groups to which logged in user belong

var groupsArr = j2js(sgroup);

var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition("u_manager_visibility_list", "IN", groupsArr);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi James,

So update code as below and check once; it should work

var sgroup = gs.getUser().getMyGroups(); // get the groups to which logged in user belong

var groupsArr = j2js(sgroup);

var qc = current.addQuery("caller_id", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition("u_manager_visibility_list", "IN", groupsArr);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

As simple as that.

So frustrating I couldn't figure this out myself.

I have one catalog form..
Variables :

GROUP

Exit_Date

Parent_Group.


If there is NO action is taken on <Exit_Date -4days> all the tasks/incidents/open tickets assigned to ( GROUP) will auto transfer to Parent_Group on <exit_date+1>

Can u please write script in scheduled jobs?

Hi Mani,

Is this something related to this question or this is a separate question

Regards

Ankur

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