Restrict problem task closure rights to the members of Specific assignment group

snehasaha
Tera Contributor

I am new to ServiceNow development. We have a requirement to restrict problem task closure rights to the members of Specific assignment group. The new assignment group say "ABC" is already created. Can someone please help on how can I proceed further? If any ACL needs to be created for this and what should be steps ? 

9 REPLIES 9

Chaitanya ILCR
Kilo Patron

Hi @snehasaha ,

it depends on how you want to achieve it 
1.you can create a write ACL on problem task table and give the access to assignment group members.

2. or You can create a before update BR for this 

ChaitanyaILCR_0-1738127811907.png

script:

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

	// Add your code here
	if(!gs.getUser().isMemberOf(current.getValue('assignment_group'))){
		gs.addErrorMessage("you cannot close this task as you are not a member of assignment group")
		current.setAbortAction(true);
	}

})(current, previous);

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

ritu_saluja
Tera Expert

Hello Sneha,

 

You can use before update Business Rule 

and use the following script

(function executeRule(current, previous /*null when async*/) {
var assignmentGroup = current.assignment_group; // Get the assignment group of the task
var userGroup = gs.getUser().getMyGroups(); // Get current user's assignment groups

// Check if the user belongs to the specific group and if task state is being changed to closed
if (userGroup.indexOf(assignmentGroup) !== -1 && current.state == 3) { // Assuming state 3 is 'Closed'
gs.addErrorMessage("You do not have permission to close this task.");
current.setAbortAction(true); // Prevents the record from being updated
}
})(current, previous);

Note: Please check the Closed State Backend value in your instance, it might be different from 3

 

Ankur Bawiskar
Tera Patron
Tera Patron

@snehasaha 

so only members of those group should close the problem_task

2 ways to do this

1) Business rule

You can have before update BR on problem_task table

Condition: State Changes to Close

Script:

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

    // Add your code here
    if (!gs.getUser().isMemberOf('ABC')) {
        gs.addErrorMessage('You cannot close the problem task as you are not member of group ');
        current.setAbortAction(true);
    }

})(current, previous);

OR

2) use onChange client script when State Changes to Closed check if logged in user is member of that group and if not then show error message and don't allow to change the state

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

Hi @Ankur Bawiskar , I tried creating a Business rule using the same steps and it is not allowing users to close the PTASK and even if the user is a part of the assignment group. Can you please advise how to allow it only to the members of ABC Assignment group ?