There are open tasks in RITM at that time the RITM (REQ) should not closed

Community Alums
Not applicable

hi there,

RITM contains multiple catalog tasks, and when the tasks are still in open state at that time the assignee try to close the RITM, at that time the RITM should not close, it should show Error message, that some tasks are still open so can't close RITM.

for this I have written one Before(Update) BR and which is working fine in UAT but in production,

When we try to assign the RITM to someone and try save the RITM at that time also the Error is coming (some tasks are still open so can't close RITM.) but this should not be happen, the error should only come when the Tasks are open

 

Please find the BR 

PriyaSm_0-1690184213322.png

 

var scTask = new GlideRecord('sc_task');

scTask.addActiveQuery();

scTask.addQuery('request_item', current.sys_id);

scTask.query();

if (scTask.hasNext()) {

    gs.addErrorMessage('There are open tasks in this RITM. Please scroll down and close all tasks. The RITM will close automatically');

    current.state = previous.state;

}

 

Can someone please help me to get the solution.

 

Thanks,

Priya

1 REPLY 1

OlaN
Giga Sage
Giga Sage

Hi,

You are on the right track, I would change two things.

First, the condition, I would change it to be "changes to" Closed complete, because you only want the check to be performed when the change of state happens.

Second, in the script you can add a line to abort the action, then it should work.

if (scTask.hasNext()) {
    gs.addErrorMessage('There are open tasks in this RITM. Please scroll down and close all tasks. The RITM will close automatically');
    current.setAbortAction(true);
}