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

Hi Avinash,

The answer provided by @Akshay Kangankar should work. But don't use 'gr' variable in script as it is not best practice and can behave weirdly, just change the variable to something else.

Thanks and Regards,
Abhijit
Community Rising Star 2022

 

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi , 

Thanks for the solution.

The Data from number (Incident table) is not getting transferred into customer incident table.

 

i am using this code :

(function executeRule(current, previous) {

    var gr = new GlideRecord('u_customer_incidents'); 
    gr.newRecord();
    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.number +" has been created");

})(current, previous);

Hello,

 

Try with 

(function executeRule(current, previous) {

    var gr = new GlideRecord('u_customer_incidents'); 
    gr.newRecord();
    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.update();
   gs.addInfoMessage("The customer incident " + gr.number +" has been created");

})(current, previous);

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

Thanks for the help