Business rule for RITM

Joyce W
Giga Expert

I am new to scripting.

I want to have a business rule that  prevents Requested Item record from closing if Catalog task is NOT in closed complete state

Thank you kindly, 

 

1 ACCEPTED SOLUTION

try this

var gr = new GlideRecord('sc_task');
gr.addQuery('requested_item', current.sys_id);
gr.addEncodeQuery('state=1^ORstate=2');

gr.addActiveQuery();
gr.query();
if (gr.next())
{
gs.addErrorMessage('There are open task records for this requested item. Please close all tasks.');
current.setAbortAction(true);
}

View solution in original post

15 REPLIES 15

Hi Joyce,

Can you share the screenshot here?

Also did you check what is the state value of those tasks?

yes you can query on active flag

whenever task is changed to complete active field is set to false

i.e. when state changes to either "Closed Complete" or "Closed Incomplete" or "Closed Skipped" active flag is set to false

update script as below; if any 1 open task found i.e. active task found then stop form submission

var gr = new GlideRecord('sc_task');

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

gr.addEncodedQuery('active=true');

gr.query();

if(gr.getRowCount() > 0){

gs.addErrorMessage('Please close all the open tasks to close the RITM');

current.setAbortAction(true);

}

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

try this

var gr = new GlideRecord('sc_task');
gr.addQuery('requested_item', current.sys_id);
gr.addEncodeQuery('state=1^ORstate=2');

gr.addActiveQuery();
gr.query();
if (gr.next())
{
gs.addErrorMessage('There are open task records for this requested item. Please close all tasks.');
current.setAbortAction(true);
}

Thank you all for your help. Very much appreciated.

This worked with minor adjustment on line 2 gr.addQuery('requested_item', current.sys_id);

field name is request_item

find_real_file.png

getRowCount is really inefficient and I would not use it

if you want to get a row count consider glideAggregate

if you are looking to see if just there is more than one record then consider gr.setLimit(1)

 

Hi Ankur ,

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

Can you please tell me what is this "request_item" in  the above code. I am not able to find any field on the RITM form with this name.

Thanks & Regards