Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Calling script include from business rule

Rajesh Sheela1
Tera Contributor

I have one requirement that copy case fields from case to incident for that i created one script include and am calling that script include from business rule. but it's not working. can anyone help me on this.

 

script include below

RajeshSheela1_0-1671025031330.png

 

Business rule below :

 

RajeshSheela1_1-1671025073228.pngRajeshSheela1_2-1671025083644.png

 

 

2 REPLIES 2

Sagar Pagar
Tera Patron

Hi @Rajesh Sheela1,

You have to pass the current object from business rule to Script include as a parameter. Use that parameter in script include.

 

Share your scripts here.

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Script include : 

 

var COPYCASEINC = Class.create();
COPYCASEINC.prototype = {
initialize: function() {},
COPYINC: function(current) {
var IncCp = new GlideRecord("incident");
IncCp.addQuery("sys_id", current.incident);
IncCp.query();
if (IncCp.next()); {
IncCp.u_asset = current.asset;
IncCp.u_account = current.account;
IncCp.u_product = current.product;
}
},
type: 'COPYCASEINC'
};

 

Business rule : it is running after insert and update

 

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

// Add your code here
//var cpInc = '';
var sc = new global.COPYCASEINC();
sc.COPYINC();

})(current, previous);