How do I automatically create child records

john_roschella
Kilo Contributor

We have a requirement that when a certain type Problem is produced (via a record producer) that 4 new incident records shall be produced.

I expect that I would be using a business rule to produce the child incident records. However, I cannot find anything in the WIKI to help in determining how to create records in a table that is different than the table on which the business rule is being executed.

Can someone help me or provide an example of code that
(1) would run when a Problem record is inserted
(2) create a record in the incident table and tie it to the problem by populating the incident.problemid value

Thanks in advance for any help you can provide.

John Roschella

3 REPLIES 3

john_roberts
Mega Guru

You would need a business rule on the problem table. Use the after event (when) and check the insert field. Define the problem type in the condition field to identify when this rule should execute.
Here's a simple example of how to create a new incident, sounds like you might benefit from templates as well.


Jerrod_Bennett
ServiceNow Employee
ServiceNow Employee

I agree with John...here's the rule that I would write:

This needs to be a business rule, on the problem table, with the 'insert' field checked (telling this rule to run when a 'Problem' is 'Inserted'). Feel free to scale it to as many incidents and as many fields as you'd like.


//Create an incident assigned to the hardware group
var incident1 = new GlideRecord('incident');
incident1.initialize();
incident1.problem_id = current.sys_id;
incident1.short_description = current.short_description;
incident1.assignment_group.setDisplayValue('Hardware');
incident1.insert();

//Create a second incident assigned to the software group
var incident2 = new GlideRecord('incident');
incident2.initialize();
incident2.problem_id = current.sys_id;
incident2.short_description = current.short_description;
incident2.assignment_group.setDisplayValue('Software');
incident2.insert();


Thanks that was a great help and we are well on the way of completing/fulfilling this requirement.

John