apply a template from a workflow activity

smithcorey
Giga Contributor

Hi all,

So, I am trying to apply a template from a workflow activity.

I tried this in the workflow activity, but to no avail, so any input or direction would be most appreciated.

task.applyTemplate('u_template__1'); //u_template__1 is the name of the template I am trying to apply
1 ACCEPTED SOLUTION

Hi Michael,



Template(s) being applied is from one of 5 template variables (each a


separate reference field to sys_template table, on the sc_cat_item table.)


The workflow iterates through each of the templates,if not empty, applies


the template.



This is what ended up working in the script area of the Catalog Task


activity



task.applyTemplate(current.cat_item.*name of the template variable goes


here*.name +'');








On Wed, Apr 1, 2015 at 11:08 AM, Michael Ritchie <


View solution in original post

5 REPLIES 5

The SN Nerd
Giga Sage
Giga Sage

Can you post a screenshot of your workflow activity?


Also, what order is your workflow set to?



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

Are you creating this task in the workflow?   If so one of the options in the create task activity is to apply a template as it is getting created.



If you are trying to apply a template to an inflight task then you can add a run script activity and put current.applyTemplate('templateName').


Hi Michael,



Thanks so much for getting back to me.



I updated my workflow and added the "Catalog Task" activity to the workflow


and then set the "Task value from Template" on the activity.


This worked perfectly when I selected a specific template.



My struggle is that I am trying to apply a template to an in-flight catalog


task. The template to be ideally applied to the catalog task is from a


reference field on the Catalog Item table called (u_template__1).


This reference field (u_template__1) has a specific value in it, but it is


"dynamic", allowing the user building the catalog item to choose various


templates. So I am trying to pull the value of whatever is stored in that


reference field (u_template__1) and apply that template.



Does that make sense?





On Tue, Mar 31, 2015 at 6:12 PM, Michael Ritchie <


Corey, thanks for the clarification.   Is there a reason you want to apply this template with the workflow?   I am thinking a better alternative is to apply it when the user sets the template in the catalog task.   You could create a business rule on the sc_task table that looks for changes in the u_template__1 field and if found execute:


current.applyTemplate(current.u_template__1)