The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Apply template server side

Lasse5
Kilo Contributor

Hello!

We have a setup from where we generate an array of tasks to a project depending on a customer input value. The relation between the projects and tasks happens through a related list.

When the user has selected the value on the project, and submitted it, the list automatically creates the tasks through a BR / sys_properties.

Each of these respective tasks which are generated through the project, should be populated depending on a template they are linked to. For example: task 1.0 is mapped to template 1.0. We have done this through a client script:

var task = g_form.getValue('task_no');

var task1_0 = 'task_id';

//var task 1_1='task_id'

etc.

if(task == "1.0"){
applyTemplate(task1_0);

This solution does work. However, the template is first applied, once the user goes into the task (due to being a client script), and is thus not loaded directly in the related list. The data first becomes visible through the related list, when the user has entered the respective tasks and saved them.

My question is then, it it possible via a client script to have the data loaded directly? Or alternatively, can I apply templates via business rules, to be able to load the data server-side?

I have been testing the various solutions posted here: https://docs.servicenow.com/bundle/london-platform-administration/page/administer/form-administration/reference/r_ScriptedTemplates.html and nothing works.

Thanks in advance!

5 REPLIES 5

What I understood from your question is that you want to create task applying templates to it. Am I right?

 

if it so you should do like this

var task = new GlideRecord('Your_table_name')

task.initialize();

task.applyTemplate('Your_template_name');

task.insert();

 

Now this can be achieved only in server side scripting. business rule script, workflow script , script include etc.