The CreatorCon Call for Content is officially open! Get started here.

How we can create 5 incident tasks through a record producer.

Anshika Bhatna1
Tera Contributor

How we can create 5 incident tasks through a record producer.

1 ACCEPTED SOLUTION

aruncr0122
Mega Guru

Use Record Producer Script (Script tab on the record producer)

In your Record Producer → Script field, you can add logic after the Incident record is created:

 

(function producerScript(current, producer) {
// current = incident record being created
// producer = record producer variables

try {
// Create 5 incident tasks linked to this incident
for (var i = 1; i <= 5; i++) {
var task = new GlideRecord("incident_task");
task.initialize();
task.incident = current.sys_id; // link to the incident
task.short_description = "Follow-up Task " + i;
task.description = "This is auto-created task number " + i + " for Incident " + current.number;
task.assignment_group = current.assignment_group; // optional, reuse Incident group
task.insert();
}
} catch (ex) {
gs.error("Error creating incident tasks: " + ex.message);
}

})(current, producer);

 

OR

Use Business Rule (if you want this to apply for all incidents, not just this record producer)

Create a Business Rule on the incident table, after insert.

Add similar logic to insert 5 incident_task records.
⚠️ But this applies to every Incident creation (not just via the record producer).

View solution in original post

6 REPLIES 6

Bhuvan
Mega Patron

@Anshika Bhatna1 

 

You can extend below logic to achieve this

 

https://www.servicenow.com/community/itsm-articles/part-1-multiple-records-creation-from-record-prod...

 

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan

@Anshika Bhatna1 

 

Did you get a chance to review this as I believe the information provided should answer your question

 

As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

Its_Azar
Tera Guru
Tera Guru

Hi there @Anshika Bhatna1 

You can do this in the record producer’s script. After creating the incident, just loop and insert 5 tasks linked to it. like this):

 

var inc = new GlideRecord("incident");
inc.initialize();
inc.short_description = producer.short_description;
var incID = inc.insert();

for (var i = 0; i < 5; i++) {
   var task = new GlideRecord("incident_task");
   task.initialize();
   task.short_description = "Task " + (i+1);
   task.parent = incID;
   task.insert();
}

Hope this helps.

 

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

abirakundu23
Mega Sage

Hi @Anshika Bhatna1 ,

Since, Record Producer create single record in ServiceNow, want to create 5 incidents tasks You can do it by record producer script or flow designer once request submitted.

Please mark helpful & correct answer if it's worthy for you.