Business Rule Insert

Avinash Dubey2
Tera Contributor

Create a Business Rule which will trigger when new record will be inserted in Incident table then create a new record in Customer Incident table 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Why not use flow designer for this with no script?

try to use this script and share the update

(function executeRule(current, previous) {

	var gr = new GlideRecord('u_customer_incidents'); 
	gr.initialize();
	gr.u_category = current.category;
	gr.u_subcategory=current.subcategory;
	gr.u_parent_inc=current.number;
	gr.u_state=current.state;
	gr.u_description=current.description;
	gr.u_short_description=current.short_description;
	gr.u_caller=current.caller;
	gr.insert();
	gs.addInfoMessage("The customer incident " + gr.getDisplayValue() +" has been created");

})(current, previous);

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

9 REPLIES 9

Community Alums
Not applicable

Hello,

Here what is "Customer Incident table". Are you talking about any third party tool. If yes then it needs integration.

 

Regards,

Akshay 

Voona Rohila
Kilo Patron
Kilo Patron

Hi Avinash

Can you explain in detail of your requirement?


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Avinash Dubey2
Tera Contributor

Customer Incident  Table:

Table Name - Customer Incidents
Fields - 
Inc Number - autogenrated number
Parent Inc Number- number
Short Description - String 250 Mandatory
Description - HTML Mandatory
State - Choice (values same as incident State field values)
Category - Choice ( Same as Incident Category field values)
Subcategory - Choice ( Same as Incident Category field values)
Caller - Reference ( ref to sys_user table filter only active records)
Assignment Group - Reference - (ref to sys_user_group table)
Assigned to - reference - (ref to sys_user table)
Additional Comments - Journal input ( same as incident)
work notes - Journal input

Detail statement :

Create a Business Rule which will trigger when new record will be inserted in Incident table then create a new record in Cusetomer Incident table with below values 
Parent Inc Number, Short Description, Description, State, Category, Subcategory, caller
*Inc Number should be autogenerated.
Once record is inserted show info message on form with new Inc number which will be created on Customer Incident table.

 

Community Alums
Not applicable

Hello @Avinash Dubey 

Create Business Rule  on incident table. PFB screen shot. 

 

find_real_file.png

 

then write script PFB sample script. Kindly add your customer table name and map all required fields as I have shown some examples

find_real_file.png

 

Sample script for easy copy paste - 

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

	var gr = new GlideRecord('customer_incident'); //enter customer incident table name
    gr.newRecord();
	gr.category = current.category;
	gr.state=current.state;
	gr.description=current.description;
	gr.short_description=current.short_description;
	gr.parent_incident=current.number;
	gr.caller=current.caller;
	//similarly mapp all required fields.
	gr.insert();
   gs.addInfoMessage("The customer incident " + gr.number +" has been created");

})(current, previous);

 

Mark āœ… Correct if this solves your issue and also mark šŸ‘ Helpful if you find my response worthy based on the impact. 

Thanks
Akshay Kangankar