ITBM using Business Rule to apply a template to a new project

Glaucco Morais
ServiceNow Employee
ServiceNow Employee

Hi Experts,

I created a scoped app that run a workflow, and in one of the steps the workflow create a new project in the pm_project table. For used a scoped app I can't use the function applyTemplate() to apply the template during the project creation.

An alternative is using the Business Rule to try to apply the template after the creation.

Does anyone know how to do it ?.

regards.
------

// Script in workflow

var sys_id = current.sys_id;
var number = current.number;
var novo_projeto = current.number+' - '+current.u_agencia.u_nome_completo;

// var template_sys_id = '399201dadb0fbb006b79465039961923';

 

var project = new GlideRecord('pm_project');
project.initialize();
project.short_description = 'Obra: '+novo_projeto;
project.calculation_time = 'manual';
project.parent = current.sys_id;
project.u_ref_sinistro_agencia = current.sys_id;

//project.applyTemplate("bb_eap"); this function don't work for scoped app.
project.insert();

 

3 REPLIES 3

sachin_namjoshi
Kilo Patron
Kilo Patron

You can apply template in scoped app using below

 

var sys_id_of_template = '56a8e507db6b26405accd5f0cf96190b';   


var grObj = new GlideRecord('incident');   


var t =   new GlideTemplate.get(sys_id_of_template);   


t.apply(grObj); 

 

Regards,

Sachin

The Machine
Kilo Sage

Project Templates are a bit different than regular templates.  If you are trying to apply a project template, try the following:

var templateId = '09a8e024db984b00d0c07d5e0f961926';
var projectId = '9ad197f6dbcf3700a383f34ebf961980';
var startDate = '2019-08-09 08:00:00';

GlideProjectTemplate.apply(templateId, projectId, startDate)

Othman2
Tera Contributor

Hello,

In order to apply "applyTemplate" form a scoped application, a workaround is to create a script include in the global application ( that is openned for all application scopes ) , and call the script include from your workflow for instance.

 

Regards,

Othman