The CreatorCon Call for Content is officially open! Get started here.

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

I am trying this BR.

Both current.state = 2; and current.state = previous.state; are not working. The state on the requested item remains "Closed complete." Have you experienced this?

I solved this by doing a current.active = true; before the current.state = previous.state;

Hi Valentina,

 

I've got this script working for me too, but the error message displays more than once.

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

 

Any idea how/where I add a hideFieldMsg in the script so that the error message only displays once?

 

Many thanks,

Anna

ankit_sharma487
Kilo Guru

just because there is already a business rule that runs to close RITM when all its TASKS are closed, so you dont need to worry about this .



NOW- before that if you want users to prevent from closing , you may run a client script ON LOAD



if(g_user.hasRole() != 'admin') // check that if loggedin user is NOT Admin , then set fireld to readonly else revoke


{


g_form.setReadOnly('state', 1);


}


if(g_user.hasRole() == 'admin')


{


g_form.setReadOnly('state', 0);


}