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

Not sure what I am doing wrong. The code does not give expected results.

Business rule is on sc_req_item table

It's running before and on update

on line 5 I am calling sc_req_item table.

The results I get is that even RITM records with no catalog tasks gives error message

I appreciate your effort.

 

find_real_file.png

Hi Joyce,

line number 5 should be having request_item instead of sc_req_item in the addQuery()

that is because request_item is the field on sc_task which stores the RITM record

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

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

I changed line 5. Thank you! That solves one problem- I can close items that have no task record.

 

Any item with task record still gets error even if the task is in closed Complete state

Hi Joyce,

Does that task belong to this RITM?

Ideally it should not;

Example: if RITM has 2 task

1 task is complete and 1 is in progress the rowcount would be 1 so it would stop

if both the tasks are complete then the rowcount would be 0 so it would allow record to be saved

Regards

Ankur

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

Task belongs to the RITM record and both tasks are on complete state. Even where the task is single record, the RITM does not update

Is it possible to check for active flag on sc_task other than rowcount