Populating an incident Field from a table using a business rule

colinmorgan
Kilo Contributor

Good day All,

I have a question that relates to business rules and scripts.

I have a custom table, lets say Table1 that contains a list of activities. Each activity has a unique number and a string field called instructions that contains a set of instructions on how to perform the activity.

I am then creating an Incident template that gets generated through Scheduling. That incident template contains a reference field which is set to the unique number I want.

The objective is that when the scheduler triggers and creates the incident request, I would like my business rule to look at the unique number in the template and then populate Field1 on the Incident form with the data from the related Instructions field from Table1.

I hope this makes a bit of sense. if anyone can help me formulate the query to achieve this that would be fantastic.

Many thank.

Colin

2 REPLIES 2

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Colin,



I have coded the sample script. Please change the table name and field column names.


Create a after Business rule (insert checked to true) on the incident table.


Script :


var gr = new GlideRecord('TABLE1 NAME HERE');


gr.addQuery('sys_id',current.u_unique); //Replace u_unique with the exact column name on the incident table that populates reference.


gr.query();


while(gr.next())


{


current.u_field1 = gr.u_instruction; //Replace u_field1 with the exact column name of the field on the incident table and "u_instruction" with the exact column name of the field which has to be copied.


current.update();


}


Thank you very much Pradeep! that worked a charm. A lot more straightforward then I anticipated too.



Have a great weekend!


Colin