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

@thrsdy1512 

the BR has interactive session check so it should work

Did you try that?

share how that message is shown

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

I'm unable to pull change request.state into the filter conditions, I only see change request as an option. I am thinking if I update the business rule script so that if change request state  assess, do not execute display the message that might be the easiest solution.

@thrsdy1512 

Basically you can hide the New button from related list of Change task when CHG is in Assess State

That's the easier option

1) configure list control on that related list

2) add this script in the"Omit new condition" field. If this field is not on form then add it in form layout in default update set

Directly go to this and make the necessary changes

URL: https://instanceName.service-now.com/nav_to.do?uri=sys_ui_list_control.do?sys_id=986553fb0a0006417a879dc40c0d683a

// if CHG is active and state is not assess then show
if (parent.active && parent.state.toString() != '-4')
    answer = false;
else
    answer = true;

Output: New button is hidden when CHG is in Assess State

AnkurBawiskar_0-1738159060368.png

 

Note: If it's some other State and not Assess then use that value in script, but logic will be same

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

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

 

@thrsdy1512 

Glad to help.

Please mark my response as correct so that it helps future members.

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