Set Value with Business Rule when all child records are Closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2024 08:34 PM
Hi All,
I want to set one field on parent table when all the child records from custom tables are closed with business Rule.
I need to check each and each record has been closed or not.
Can anyone help me with this.
Thanks & Regards,
Rohini
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 08:24 AM
Hi @rohiniv
Might be give you an idea
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2024 12:43 PM - edited 03-29-2024 01:03 PM
Hi @rohiniv ,
you can try with the below code ,
Here i have taken RITM table as parent and child as sc task make the changes according to your requirement,
var gr = new GlideRecord("sc_req_item");
gr.addEncodedQuery("state=1"); // state is open
gr.query();
while(gr.next()) {
var closedCount = 0;
var taskRec = new GlideRecord("sc_task");
taskRec.addQuery("request_item", gr.sys_id);
taskRec.query();
var totalCount = taskRec.getRowCount();
while(taskRec.next()){
if(taskRec.active.toString() == 'false')
{
closedCount++;
}
}
if(closedCount == totalCount && totalCount != 0)
{
gr.state = '3'; // update the parent field
gr.update();
}
}
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang