applyTemplate() with child templates and references

Antal1
Tera Contributor

I would like to trigger creating multiple tasks with a UI action from a parent without the need to hardcode everything.

I see there is a Next Related Child Template reference on the templates (sys_template) where I can chain task after task. Creating the first task with the following script creates the task, applies the template, also creates all the chained tasks but only the first task will have the reference to the parent. So the following tasks will not be linked anywhere and are worthless like that. How should this be resolved?

var gt = new GlideRecord('rm_scrum_task');

gt.initialize();

gt.parent = current.sys_id;

gt.applyTemplate('template 01');

//gt.insert();

6 REPLIES 6

saprem_d
Giga Guru

Hi,



Please use "link element" field to determine which field would be used for linkage.



Also, below kb article could help you



ServiceNow KB: Records created via Parent and Child Templates are not properly linked (KB0598164)


Antal1
Tera Contributor

Hi, thanks for the quick answer.


I set the link element to parent. Now the second task has the first task referenced which was created from template 01, not the parent record.


Hi,



You need to utilize "next related template" field also



Consider an examaple



Change record is getting created through 1 template which has a child template to associate change task. Now one more task needs to be created through another template. This template would be put in "next related template" field of the first task's template.


Antal1
Tera Contributor

Next related template does not work for me, the next task does not get created.