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.

Prevent Problem Task Closure When Associated Change Request Is Not Closed

Akhila P
Tera Contributor

Hello all,

We encountered an issue where a Problem Task is getting updated to Closed even if the associated Change Request is not in a closed state. The system displayed an error message but still updated the state. To fix this, I tried modifying a Business Rule that checks the related Change Request before allowing the Problem Task to close using the task_rel_task table. However, this approach didn’t work because task_rel_task had no records for the relationship.

How do I check the associated Change Request for a Problem Task from the related list in the most efficient way?

Also Iam attaching few screenshots for your refernce

Your help is very much needed! Any best practices or alternative solutions would be greatly appreciated..

Thank You!

4 REPLIES 4

Anand2799
Tera Guru

Hi @Akhila P ,

 

Update your business rule with this script: 

(function executeRule(current, previous /*null when async*/ ) {
    var isActiveChangeExist = false;
    var grChange = new GlideRecord('change_request');
    grChange.addQuery('parent', current.getUniqueValue());
    grChange.addActiveQuery();
    grChange.setLimit(1);
    grChange.query();
    if (grChange.hasNext()) {
        isActiveChangeExist = true;
    }
    if (isActiveChangeExist) {
        gs.addErrorMessage(gs.getMessage("Please close related change request before closing problem task"));
        gs.setRedirectURL(current);
        current.setAbortAction(true);
    }

})(current, previous);

 

Thanks

Anand

Hello @ Anand2799 ,

 

I have updated the script with the changes you provided. It is working partially — the error message is appearing as expected, but the state is still updating to Closed

What other things do I need to add to ensure the state does not change when the error message is displayed?

Thank You,

Akhila

Can you share some screenshots where you don't want to show Closed state?

 

Alternatively, you can also create a script include and add it to the UI Action condition, so it will only be available when change request gets completed. However, if you don't want to modify OOB UI Action then BR need to be used.

Ankur Bawiskar
Tera Patron
Tera Patron

@Akhila P 

if the agents are closing from UI action then you can show that UI action only when other task is closed.

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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