logo

NJP

Normal Change Request Templates - How To

Import · Sep 16, 2020 · article

Hi All - Just in case it is of any use to you. I have found a way to create templates for 'Normal Change Requests' without amending our workflows and keeping everything tidy.

Background:- In our organisation we have a 'Standard Change' template catalogue, which is great for pre-approved changes that do not need to go through CAB, but what about Change Templates that could be used which carry pre-designed information and tasks and also go through the 'Normal Change' workflow?

After a long time head scratching, we found the answer and it was more simple than we thought

1. Create a new field on your Change Request form (We called ours Change Template):

In order for the user to be able to select from a list of normal changes, a new field is required on the Change Request form. Navigate to ‘Tables’ > Change Request and select New.

Choose ‘Change Request’ in the Table field.

Choose ‘Reference’ in the Type field.

Type ‘Change Template’ in the Column label field

Under the ‘Reference Specification’ tab you will need to build out your reference qualifier in order for ServiceNow to provide you with the correct templates once done.

Choose Template in the Reference field

Then build out your reference qualifier

Table is Change_Request

and

User is(dynamic) Me

or

Group is(dynamic) One of My Groups

or

Global is True

and

Active is True

and

Class is Template

Once done, update it and add your required ACLs then proceed to place it where you want on your Change Request form.

2. Create a Business Rule

In order for this field to work in the way that you want, a Business Rule is required. On a Change Request record select the context menu then ‘Configure’ > ‘Business Rules’.

Select ‘New’ and start building your Business Rule

Ensure that you work off of the Change_Request table and that 'Active' and 'Advanced' are ticked.

Under 'When to run'

When = after

Insert = true

Update = true

Filter conditions are:

Change Template = Changes

and

Change Template = is not empty

In the 'Advanced' tab, enter the code below:

In the ‘Advanced’ tab enter copy and paste the code below into the ‘script’ field:

(function executeRule(current, previous /*null when async*/) {

//current.applyTemplate(current.u_change_template.getDisplayValue());

var temp = current.u_change_template.getRefRecord();

if (temp.next_child){

var childTemp = temp.next_child.getRefRecord();

applyNextChild(childTemp);

}

function applyNextChild(temp){

var childTask = new GlideRecord(temp.table);

childTask.initialize();

childTask[temp.link_element] = current.sys_id;

childTask.applyTemplate(temp.name);

childTask.insert();

if (JSUtil.notNil(temp.next))

applyNextChild(temp.next.getRefRecord());

}

})(current, previous);

3. Create a Client Script

In order for the Change Template to act the way you want it to, a Client Script is required. On a Change Request record select the context menu then ‘Configure’ > ‘Client Scripts’.

Select ‘New’ and start building your Client Script.

Table = Change_Request

UI Type = Desktop

Type = onChange

Field name = Change Template

Active = True

Inherited = True

Global = True

Then paste the script below into the 'Script field'

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

if (isLoading || newValue === '') {

return;

}

//Type appropriate comment here, and begin script below

applyTemplate(g_form.getValue('u_change_template'));

}

4. Finally Building your templates

This is too big to document on here so I have pasted the official release notes

https://docs.servicenow.com/bundle/paris-platform-administration/page/administer/form-administration...

If you have done all of this correctly then it should work for you.

Thanks

View original source

https://www.servicenow.com/community/itsm-articles/normal-change-request-templates-how-to/ta-p/2310822