Prevent RITM from getting closed if any of its TASK is still open. How to Achieve?

aamir1
Mega Expert

Hi,

I want to Prevent users from closing RITM if any of its TASK is still open.

Any help is highly appreciated.

Thanks,

Aamir

1 ACCEPTED SOLUTION

Hi Aamir,


you are right, I missed it, you have to set the state to the previous value as well:



      var task = new GlideRecord('sc_task');


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


      task.addActiveQuery();


      task.query();


      if(task.hasNext()){


              gs.addErrorMessage('Please, close all Tasks before to close the Request Item');


              current.state = 2;


      }



Regards,


Valentina


View solution in original post

8 REPLIES 8

Valentina6
Giga Guru

Hi Aamir,


I suggest to create a 'before' Business Rule on 'update' of sc_req_item table.



Conditions: State changes to 'Closed'


Script:


      var task = new GlideRecord('sc_task');


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


      task.addActiveQuery();


      task.query();


      if(task.hasNext()){


              gs.addErrorMessage('Please, close all Tasks before to close the Request Item');


      }




Hope it helps!



Regards,


Valentina


Hi Valentina,


It displays the error message but also updates the state from open to closed.


I tried current.setAbortAction(true);


But no luck. Any idea how to do this?


Hi Aamir,


you are right, I missed it, you have to set the state to the previous value as well:



      var task = new GlideRecord('sc_task');


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


      task.addActiveQuery();


      task.query();


      if(task.hasNext()){


              gs.addErrorMessage('Please, close all Tasks before to close the Request Item');


              current.state = 2;


      }



Regards,


Valentina


Thanks. It worked. But used current.state = previous.state; instead of current.state = 2; to make it more dynamic.



Thanks for your help.