Querying task table from INC using BR

SathiskumarD
Tera Contributor

How to query task table from Incident table and update the value  using business rule? 

1 ACCEPTED SOLUTION

J_31
Kilo Sage
To query the Task table from the Incident table and update the value using a business rule in ServiceNow, you can follow these steps:
 
1. Navigate to the "Business Rules" module in ServiceNow and select "New".
2. Name your business rule and select the "Table" for which you want to apply the rule, in this case, the Incident table.
3. Under the "Advanced" tab, write the script to query the Task table and update the value. Here's an example script:
 

//Query the Task table for records related to the current Incident
var taskGr = new GlideRecord('task');
taskGr.addQuery('parent', current.sys_id);
taskGr.query();

//Update the value of a field in each related task record
while (taskGr.next()) {
  taskGr.setValue('state', 'Closed Complete');
  taskGr.update();
}
This script will query the Task table for records that are related to the current Incident (the one being saved), and then update the "state" field of each related task record to "Closed Complete".

 
 
 
 
 

View solution in original post

3 REPLIES 3

J_31
Kilo Sage
To query the Task table from the Incident table and update the value using a business rule in ServiceNow, you can follow these steps:
 
1. Navigate to the "Business Rules" module in ServiceNow and select "New".
2. Name your business rule and select the "Table" for which you want to apply the rule, in this case, the Incident table.
3. Under the "Advanced" tab, write the script to query the Task table and update the value. Here's an example script:
 

//Query the Task table for records related to the current Incident
var taskGr = new GlideRecord('task');
taskGr.addQuery('parent', current.sys_id);
taskGr.query();

//Update the value of a field in each related task record
while (taskGr.next()) {
  taskGr.setValue('state', 'Closed Complete');
  taskGr.update();
}
This script will query the Task table for records that are related to the current Incident (the one being saved), and then update the "state" field of each related task record to "Closed Complete".

 
 
 
 
 

Bert_c1
Kilo Patron

The incident table is a child table of task, and inherits the fields from task.  What field do you want to update on that task table record? Just set current.[field_name] to desired value in a simple script in a "Before" BR that runs on "Insert", "Update"

I have custom field on task table. I created a before update and insert BR on task table. However, they want BR on incident table instead of task table. So I am glide-querying the task table to update custom field on task table.