applyTemplate() with child templates and references
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 05:03 AM
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();
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 05:11 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 05:23 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 05:44 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2017 05:49 AM
Next related template does not work for me, the next task does not get created.