Close change tasks before closing chage

srujana2
Tera Contributor

HI all,

I want to show Error message, if there are any open change tasks before closing change and form not going to submit(close) .

Here i wrote before business rule on change_request table

before update

when to run : state changes to closed

var activeTask = new GlideRecord('change_task');
activeTask.addQuery('active',true);
activeTask.addQuery('change_request', current.sys_id);
activeTask.query();
if (activeTask.next()) {
gs.addErrorMessage('This Change Request has currently opened tasks, and cannot be closed. Please close any open tasks before closing this Requested Item');
current.state = previous.state;
current.setAbortAction(true);
}

I followed 1 link..but it is not working for me..

I am able to close change before closing change tasks ..and it doesn't shows error message..

after closing the change, change tasks will get cancelled..

How to fix..

Thanks in advance..

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Try adding logs

update as below

var activeTask = new GlideRecord('change_task');
activeTask.addQuery('active',true);
activeTask.addQuery('change_request', current.sys_id);
activeTask.query();
if (activeTask.next()) {

gs.addInfoMessage('Inside if');
gs.addErrorMessage('This Change Request has currently opened tasks, and cannot be closed. Please close any open tasks before closing this Requested Item');

current.setAbortAction(true);
}

Regards
Ankur

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

View solution in original post

9 REPLIES 9

@srujana 

Hope you are doing good.

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

 

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

Long6
Tera Contributor

There is an OOB BR for your requirement, why do you need to create new BR?

Check open change_tasks

srujana2
Tera Contributor

Hi,

But it is not working..i dont know why?

 

@srujana 

Did you try adding logs

please share BR condition

It should be before Update

Regards
Ankur

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

Jaspal Singh
Mega Patron
Mega Patron

Hi Srujana,

 

Business rule seems to be fine. Can you check if there is some other Business rule that runs on before insert/update with an Order lower than the one that you use above.