Assignment Group Can Only be used by Those in the Group

Wasdom_Kung
Tera Guru

Hello, 

 

I have been asked to 'lock down' an assignment group, this group can be viewed from the assignment group field on the incident form (We already have this set to only display specific groups that match 'types' set in the dictionary).

I am looking to implement the following: If someone is in the group (say Group 1) then check if this user is also in that group on submission of the incident, if not clear the field and display an error. If they are in the group on submission, keep populated and save incident. 

 

How could I achieve this? Or if someone has done something similar, that'd be great!

 

Thanks,

1 ACCEPTED SOLUTION

SunilKumar_P
Giga Sage

Hi @Wasdom_Kung, If you want to restrict the incident creation when the logged in user is not part of the assignment group, you can create a Before Insert Business Rule.

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

    if (!gs.getUser().isMemberOf(current.assignment_group)) {
        gs.addErrorMessage("You are not an member of Assignemt group.");
        current.setAbortAction(true);
    }

})(current, previous);

 

Regards,

Sunil

View solution in original post

11 REPLIES 11

bradleydebono
Mega Guru

Good day, 

It sounds like you want a Business Rule pointing at the incident table. 

 

You want to check "advanced" and ensure the business rule runs "Before" the "Insert" and "Update" operations.

 

The code will look something like this...

 

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

	function checkGroupMembership(group, user) {
		var gr = new GlideRecord("sys_user_grmember");
		gr.addQuery("group", group);
		gr.addQuery("user", user);
		gr.query();

		if (gr.hasNext()) {
			return true;
		} else {
			return false;
		}
	}

	if (checkGroupMembership(current.assignment_group, gs.getUserID()) == false) {
		gs.addErrorMessage("Operation aborted - you are not a member of this assignment group");
		current.setAbortAction(true);
	}

})(current, previous);

 

If this helped you, please mark it as the solution, it really helps me!

 

Hi

It doesn't look like this specifies a group - I don't want it to run for every group, just a specific one. 

So group 1 should only be able to be assigned to by people in group 1, however group 2-infinity can be assigned to by anyone, if that makes sense.

Good day, 

 

You could add "assignment group = <the one(s) you want>" to the condition on the Business Rule!