business rule to prevent closing of a record if child task records are not closed

patricklatella
Mega Sage

hi all,

In a custom scoped app "Feedback", I have a custom table (extended off Task) for feedback records (let's call this the parent table).   I have a 2nd custom table (also extended off Task) for the tasks assigned to a feedback record (let's call this the child table).   I configured the 2nd table to be a related list on the records of the 1st table...so that tasks can be created and assigned associated with a feedback record.   I need a business rule to make it so the State of the parent feedback record cannot be closed if any of the associated tasks in the related list on a particular record are not closed.

I'm struggling a little with the script...thanks!

9 REPLIES 9

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Patrick,



Create a business rule on parent table with script as. Adjust it accordingly.


Also apply filter condition in the Business rule as appropriate so that the rule is triggered only in that case.


var gr = new GlideRecord('pass child table name');


gr.addQuery('parent', current.sys_id); //Repalce parent with exact field column name of field on child table which referencs parent table


gr.addQuery('state', '!=', 1); //Here replace state with exact column name of state on child table and with exact value


gr.query();


while(gr.next()){


  current.setAbortAction(true); //abort the record


}



patricklatella
Mega Sage

thanks Pradeep, I'll give it a shot!


patricklatella
Mega Sage

couple quick questions...I'm new creating business rules.   Step by step, please let me know if I've got this correct.



System Definition>Business rules



create New



create name, and select the table, which for this will be my parent "Feedback" table



check the "Advanced" box



under the "Advanced" tab, that's where I enter the code you sent.



correct so far?


You are correct so far. Also make sure insert and update checkbox set to true.