Preventing SCTASK Closure if Linked CHGs Are Still Open

LeighAnnB
Tera Contributor

I’m trying to prevent catalog tasks (SCTASKs) from being closed if there are still open change requests (CHGs) linked to them.

I know that it’s possible to block RITMs from closing when they have open SCTASKs. For reference, here’s an Business Rule I found that is used for RITMs (LINK)

 

 
Table: Requested Item
When to Run: Before Update
Condition: State is One of Closed States
Script:
(function executeRule(current, previous) {
var scTask = new GlideRecord('sc_task');
scTask.addActiveQuery();
scTask.addQuery('request_item', current.sys_id);
scTask.query();
if (scTask.hasNext()) {
gs.addErrorMessage('RITM cannot be closed until all tasks are closed');
current.state = previous.state;
}
})(current, previous);
 
If a CHG is created as part of an SCTASK, ServiceNow treats the SCTASK as the parent of the CHG, similar to how RITMs are children of SCTASKs. Just because it seems like the parent/chile relationship is the same or similar, doesn't mean it actually is.  My question is: can the same approach be applied so that SCTASKs cannot be closed if they have open child CHGs? If so, what would be the recommended field to query and best practices for implementing it?

 

Thanks in advance for any guidance!

0 REPLIES 0