how to close Ritm when all SCTask close And get error message user to try close Ritm when any one Sctask is in open state.?

suresh40
Tera Contributor

Hi All,

I have written business rule on ritm and sc task table 

1) if user try to close ritm , it shouldn't close and get error message and revert back to pervious state. Its working fine 

Businees rule:

Table Sc_req_item

 Before Update BR condition is this

State [IS ONE OF] [Closed Complete, Closed Incomplete, Closed Skipped]

order 1000

var gr = new GlideRecord("sc_task");
gr.addQuery("request_item", current.sys_id);
gr.query();
while (gr.next()) {
if (gr.active == true) {
gs.addErrorMessage("Please close all Sc Tasks and then close RITM");
current.setAbortAction(true);
}
}

 

2) When all sc task close ritm has to close automatically its also working fine .

Business Rule :

Table sc_task

 After Update BR condition is  Active changes to false 

Order 1000

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addQuery('active', true);
gr.query();
if (!gr.next()) {
var ritm = current.request_item.getRefRecord();
ritm.state = 3;
ritm.update();
}

 

Now my issue is user raising the ticket ,for one RITM multiple sctask is there , If user try close the sctask its redirecting to ritm and its showing Error message . My requirement is user try close the SCTASK ticket don't show error message . if user try close Ritm, if any one sc task is open state then error message has to visible . Please help me on this.

 

Thanks,

Suresh

14 REPLIES 14

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Update on sc_task is causing the BR on RITM to run

in the BR of sc_req_item add this

State [IS ONE OF] [Closed Complete, Closed Incomplete, Closed Skipped] AND gs.getSession().isInteractive()

BR on sc_task

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.request_item);
gr.addQuery('active', true);
gr.addQuery('sys_id', '!=', current.sys_id);
gr.query();
if (!gr.next()) {
    var ritm = current.request_item.getRefRecord();
    ritm.state = 3;
    ritm.update();
}

Regards
Ankur

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

Hi Ankur,

Its not working

Hi,

why are you allowing to close RITM from UI action or from user? restrict the state field for user so that they don't change it

ideally RITM should get closed once all catalog tasks are closed.

this is the standard practice being followed

Regards
Ankur

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

Hi Ankur,

 

Some of the Ritm will not have sctask then how can we close the ritm if state fields is read only means.

Vishnu Prasad K
Giga Guru

Hi Suresh,

 

The 2nd BR is triggering when you close the last SCTASK and it then causes the 1st BR to run as the RITM record is getting updated.

This is because of the order of the BR, not only the ones you added over here, but the OOTB BRs for setting the active flag as false.

Check the order of the BR that changes the active flag to false on RITM table and the Catalog task table (OOTB BRs). Also change the active query to a query with the state values on both the BR. 'if (gr.active == true)', keep this line in gr query and replace active with state values. You may also need to reduce the order of execution of the BR on catalog task table.