I want to create 5 incident tasks whenever priority field changes to critical

JayachandrReddy
Tera Contributor
 
8 REPLIES 8

IMG_20241224_122206.jpg

 

I have created like this, it's creating only one incident task record

Runjay Patel
Giga Sage

Hi @JayachandrReddy ,

 

use async business rule on incident table, use below code.

 

// Check if priority is set to Critical
if (current.priority == 1) { 
for (var i = 0; i < 5; i++) {
var task = new GlideRecord('incident_task');
task.initialize();
task.incident = current.sys_id;
task.short_description = 'Follow up task for Critical priority incident';
task.priority = 1; // Set task priority to Critical
task.insert();
}
}

 

Accept and like the solution if it helped.

christopher_cox
ServiceNow Employee
ServiceNow Employee

You can use a business rule to run when Priority Changes to 1 - Critical 

You can also use the following Condition current.priority.changesTo('1');

You can also put an if in the script to check for that condition.  

 

var numberOfTasks = 5;

var shortDescription = "Critical Incident task";

for (var i = 0; i < numberOfTasks; i++) {

var task = new GlideRecord('incident_task');

task.initialize(); task.parent = current.sys_id;

task.short_description = shortDescription; task.insert();

}

Add any logging necessary if you'd like.

 

Please mark helpful if you found it to be. 

Gangadhar Ravi
Giga Sage
Giga Sage

@JayachandrReddy you achieve it with flow designer. please find more details in bellow course. 

 

https://nowlearning.servicenow.com/lxp/en/now-platform/flow-designer-fundamentals?id=learning_path_p....

 

Please mark my answer correct and helpful if this works for you.