Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How can I prevent Change Request from closing until all Change Tasks are complete?

sburke
Kilo Explorer

I need a way to prevent the Request for Change from being closed until all Change Tasks (Ctasks) have been closed.   The valid state(s) for change tasks being complete are (state =3 (closed complete), 4 (closed incomplete) or 7(closed skipped) otherwise a message should appear that open Tasks must be closed first before closing the RFC.   I believe a business rule script is needed, but not familiar with writing scripts.   I had tried the below script that I found on the community, but it is not working for me.

Currently when I close a RFC, all tasks are marked as closed complete automatically (same user and date/time stamp as the RFC closure) and cannot find why/ where this is happening.

Thanks in advance for any help!

find_real_file.png

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Instead of checking the state of change request in the script, put them in the filter conditions for the business rule, like state changes to Closed. Then in the script use this



var target= new GlideRecord("change_task");


target.addQuery("change_request",current.getValue("sys_id"));


target.addActiveQuery();


target.query();


if(target.hasNext()){


gs.addInfoMessage("your message");


current.setAbortAction(true);


}


View solution in original post

7 REPLIES 7

Working great. 

Thanks Abhinay.

Abhinay Erra
Giga Sage

Glad you got this working


Vedanti_
Tera Contributor

 

Do we have do we have something OOB to Prevent Change Request Closure if it has opened change Tasks?

 

I have implemented the business rule as suggested by @Abhinay Erra  but it seems there is already some configuration preventing the closure of change request if ctask is open. I would appreciate some help here to identify the OOB configuration.

 

Below is the snapshot of an error message for OOB configuration.

 

Vedanti__0-1763060872921.png