Wednesday, May 20, 2015

How to create a record into a custom table using business rule in service now?


This blog explains about how to create a business rule to create a record into custom table.

Scenario : Whenever new incident created, Newly created Incident Number and description should stored into a custom table called 'incident_backup' table


- Create a new table called 'incident_backup' with 'description' and 'number' fields.

- Launch 'Create New' Incident module

- Right click on 'Create New' incident form header -> Configure -> Business Rule

- Create a new business rule

- Give a valid name to the business rule

- When to run ? Choose 'Insert'

- Select 'Advance' check box

- Write a function as below

createIncidentBackupRecord();  // Invoking a function
// Function definition as follows below

function createIncidentBackupRecord(){
try{
// Create a glide record for the 'incident-backup' table
var gr = new GlideRecord("incident_backup");
gr.initialize();
// Set event start, event end, name

gr.short_description=current.short_description;
gr.number=current.number;

gr.insert();

}catch(Exception){
gs.log(" Create Incident Backup Record Exception Occured while creating Blackout Window"+Exception);

}
}

- Save the Business Rule

- Create a new incident record, as soon as new incident row get created, this will trigger above business rule, and this business rule will create a new record into 'incident_backup' table



No comments:

Post a Comment