How to prevent users from creating a new change task record?

thrsdy1512
Tera Expert

 

 

I need to prevent users from being able to create new change tasks where type = type A, these tasks can only be created automatically when a Change Request is progressed to the Assess state.

I have a before insert business rule that is running on the change_task table where the task type = type A to prevent submission & display error message, which works.

 

The issue I have is when a Change Request move to the Assess state, the change request is displaying the error message. the change task is being created automatically &  and it shows in the change_task table as being created by the same user ID as the person creating the change req. I want this error msg to only be displayed on the change task itself where a user is creating it directly from the change_task table.

 

How can I prevent this error message from being displayed on the change request form when the change req state triggers the creation of the task type = type a.

 

Business rule is:

 

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

    if (current.change_task_type == 'peer_review') {
     

         
            gs.addErrorMessage('This task cannot be created by users. This  can only be created by the system when progressing a Change request.');

            // Prevent the record from being saved
            current.setAbortAction(true);
        }
    }
)(current, previous);
1 ACCEPTED SOLUTION

I was able to reach a solution by setting the following filter conditions on my business rule, have tested it across different scenarios and seems to be doing what I needed, thank you for you suggestion of using filters, wouldn't have thought of doing it this way otherwise:

thrsdy1512_0-1738159207004.png

 

View solution in original post

10 REPLIES 10

Sandeep Rajput
Tera Patron
Tera Patron

@thrsdy1512 Please update the business rule script as follows and see if it works for you.

 

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

    if (current.change_task_type == 'peer_review'&&current.parent.state!='-4') { 
     

         
            gs.addErrorMessage('This task cannot be created by users. This  can only be created by the system when progressing a Change request.');

            // Prevent the record from being saved
            current.setAbortAction(true);
        }
    }
)(current, previous);

Unfortunately this didn't work. The message still displays when the change request moves to Assess and a task is created automatically. I want to the message to only display if a user is creating a new task directly from the change task table. 

Ankur Bawiskar
Tera Patron
Tera Patron

@thrsdy1512 

2 ways

1) don't show New button when the CHG State = Assess, this can be handled via Table level CREATE ACL

OR

2) Before insert BR

you can do this without scripting as well. you need to add the interactive session check so that this BR stops insertion only when some user tries to create task and not when it gets created from backend

BR Condition: gs.getSession().isInteractive()

AnkurBawiskar_0-1738156351804.png

 

AnkurBawiskar_1-1738156365043.png

 

AnkurBawiskar_2-1738156375797.png

 

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

There ACLs in place that hide the 'New' button from the related lists tab on a change request, I am trying to prevent users from clicking 'New' in the change task table and creating the tasks that way. I have been able to prevent submit on these but the error message is displaying on change requests where tasks are generated automatically as part of progressing the change to the next stage. I need the error message to be hidden if the task is created by transitioning the change state from New to Assess.