Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

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

HI Ankur,

Now also I am able to close change ,then tasks are getting cancelled..

find_real_file.png

Hi,

please share BR condition

Also did you check by adding logs in your BR script

Regards
Ankur

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

@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