Create Template from Script

Dan Tolgyesi1
Tera Expert

Hi,

Does anyone know if there is anyway that I can create a template "sys_template" from a business rule populating the template field using values from a from on a table?

I have created an "Event Management" Table with an Event Task table. Sometimes event tasks need to be schduled so I need to be able to create a scheduled job (Which I have managed to do via a business rule) and create a template for "Event Task" and fill in the template fields.

Thanks in advance for any help
Dan

6 REPLIES 6

Kostya
Tera Guru

Hello,

I did not quite understood the second part of your question. But, yes you can create a "sys_template" record with GlideRecord described here https://wiki.servicenow.com/index.php?title=GlideRecord. I did not found any table "Event Task". Is it something custom or do you mean an sysevent table?

You need an onBefore or onAfter Update Business Rule that initialize new GlideRecord for table "sys_template" and sets the variables of the template.

This might look like


var gr = new GlideRecord("sys_template");
gr.initilize();
gr.table = 'incident';
gr.template = 'short_description=TEST^incident_state=3';
gr.insert();


But it is not possible create a template for some internal tables.

Kind regards


Hit the Thumb Icon and/or mark as Correct, if my answer was correct. So you help others to see correct responses and I get fame 🙂

Cheers,
Kostya

Hi Konstantin,

Many thanks for your response. This is very much what I am looking for.

I have managed to get the template created and the table fields to appear in the template section, but I am unable to figure out how to populate the template variables using the populated variables from the screen, the output I am getting is "current.task.title" instead of the value.

The script I am using is: -



var etask = new GlideRecord("sys_template");

etask.initialize();
etask.table = 'u_event_task';
etask.name = current.number + " - Event Task";
etask.short_description = current.u_task_title;
etask.template ='assignment_group=current.u_task.resolver_group^short_description=current.u_task_title^description=current.u_task_description';

etask.insert();


The Event table I have created is custom used for ITIL Event Management.

Thank you,

Dan


Hi Konstantin,

Many thanks for your response. This is very much what I am looking for.

I have managed to get the template created and the table fields to appear in the template section, but I am unable to figure out how to populate the template variables using the populated variables from the screen, the output I am getting is "current.task.title" instead of the value.

The script I am using is: -



var etask = new GlideRecord("sys_template");

etask.initialize();
etask.table = 'u_event_task';
etask.name = current.number + " - Event Task";
etask.short_description = current.u_task_title;
etask.template ='assignment_group=current.u_task.resolver_group^short_description=current.u_task_title^description=current.u_task_description';

etask.insert();


The Event table I have created is custom used for ITIL Event Management.

Thank you,

Dan


Hi Konstantin,

Many thanks for your response. This is very much what I am looking for.

I have managed to get the template created and the table fields to appear in the template section, but I am unable to figure out how to populate the template variables using the populated variables from the screen, the output I am getting is "current.task.title" instead of the value.

The script I am using is: -



var etask = new GlideRecord("sys_template");

etask.initialize();
etask.table = 'u_event_task';
etask.name = current.number + " - Event Task";
etask.short_description = current.u_task_title;
etask.template ='assignment_group=current.u_task.resolver_group^short_description=current.u_task_title^description=current.u_task_description';

etask.insert();


The Event table I have created is custom used for ITIL Event Management.

Thank you,

Dan