shaunmillin
ServiceNow Employee
ServiceNow Employee

In this blog post we are going to dive into how to automate the open and close of an incident using a template. Using a template will allow us to painlessly automate the record with out using code.

First we need to create a template. You can find some of the official documentation here.   https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/administer/form_administration/ta...

To create a template from an incident first create a dummy incident. Why do I do it this way? Well let's face it. It is a lot easier to fill out an incident then try and map fields in the template creator.

First, create a template from an incident to generate an basic incident.   It is much easier to populate the incident fields than to map fields through the template creator.

Next ensure you can see the template bar on the form for the incident. If you cant turn it on like this. In UI 16. blog1.png

And in UI 15 right click the form header and enable the template bar.

Next click this at the bottom of the page:

blog2.png

Fill in the form that opens:

blog3.png

Make sure all the fields that are mapped are the way you want.

******Remove the date created ******

Second, repeat Step one for what the incident should look like when closed.

******Remove the date closed ******

Third, lets take a look at what the code looks like to create an incident from a template.

var rec1 = new GlideRecord("incident");

rec1.initialize();

rec1.applyTemplate("Name_Of_my_Open_incident_template")

rec1.insert();

Fourth, lets see what the code looks like to close this incident.

var rec2 = new GlideRecord("incident");

rec2.get("SysID_OF_The_Incident" );

rec2.applyTemplate("Name_Of_my_Close_incident_template")

rec2.update();

Done this will allow the automatic creation and closure of incidents.

4 Comments