Need to restrict the close of catalog task

vinuth v
Tera Expert

Hi All,

Query 

1) Only the ITIL user who is part of the assignment group can close the catalog Task. (Admins are allowed)
2) Persons who are not part of groups are restricted to close the catalog task.
3) Requester who has raised the request are allowed to close the catalog task

 

Please any one provide me the input,

 

Thanks in advance,

Vinuth

9 REPLIES 9

@vinuth v 

UI action condition I shared should work fine.

Did you debug that UI action condition?

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

Hi @Ankur Bawiskar 

 

I tried like this but it's not working

vinuthv_1-1688474304788.png

 

vinuthv_2-1688474330421.png

 

Thanks,

Vinuth

@vinuth v 

few changes

1) you didn't select the form button or any other checkbox then how that UI action will be shown

2) also are you sure u_requested_by field is populated with the user sysId

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

zamriy
Tera Contributor

Step 1: Create a Business Rule

  1. Navigate to System Definition > Business Rules.
  2. Click New.
  3. Fill in the form:
    • Name: A descriptive name like "Restrict Task Closure to Assignment Group".
    • Table: Select the task table you need to restrict (e.g., sc_task, incident, problem_task).
    • Active: Ensure this is checked.
    • Advanced: Click the "Advanced" tab and check the Advanced box. 

Step 2: Set the condition

  • Under the When to run tab, set the following:
    • When: before.
    • Operation: update.
    • Condition: While the "advanced" tab is used for the script, you can add the condition here as a first check, although the script will perform the primary validation. For example, Assignment group is not empty. 

Step 3: Add the script

  • In the Advanced tab, add the following script to the Script field. This script checks if the current user is a member of the task's assignment group. If not, it adds an error message and prevents the update (closure) from happening. 

JavaScript

 

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

 

    // Check if the user is a member of the task's assignment group

    if (!gs.getUser().isMemberOf(current.getValue('assignment_group'))) {

        gs.addErrorMessage("You cannot close this task because you are not a member of the assignment group.");

        current.setAbortAction(true);

    }

 

})(current, previous);

zamriy
Tera Contributor

 

Step 1: Create a Business Rule

  1. Navigate to System Definition > Business Rules.
  2. Click New.
  3. Fill in the form:
    • Name: A descriptive name like "Restrict Task Closure to Assignment Group".
    • Table: Select the task table you need to restrict (e.g., sc_task, incident, problem_task).
    • Active: Ensure this is checked.
    • Advanced: Click the "Advanced" tab and check the Advanced box. 

Step 2: Set the condition

  • Under the When to run tab, set the following:
    • When: before.
    • Operation: update.
    • Condition: While the "advanced" tab is used for the script, you can add the condition here as a first check, although the script will perform the primary validation. For example, Assignment group is not empty. 

Step 3: Add the script

  • In the Advanced tab, add the following script to the Script field. This script checks if the current user is a member of the task's assignment group. If not, it adds an error message and prevents the update (closure) from happening. 

JavaScript

 

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

 

    // Check if the user is a member of the task's assignment group

    if (!gs.getUser().isMemberOf(current.getValue('assignment_group'))) {

        gs.addErrorMessage("You cannot close this task because you are not a member of the assignment group.");

        current.setAbortAction(true);

    }

 

})(current, previous);