How to call a script include function from Business rule

PRASHANTHI SATH
Tera Contributor

Dear,

 

I've written a script include and I wanted to call a function from that creates a record in another application from ServiceNow.

I've configured the business rule as,

PRASHANTHISATH_0-1739434429939.png

PRASHANTHISATH_1-1739434492514.png

 Can you please tell what is the mistake here.

 

Regards,

Prashanthi Sathri

 

1 ACCEPTED SOLUTION

maheshkhatal
Mega Sage

@PRASHANTHI SATH ,  You can execute the script include in the following manner,

If your script include looks like the one given below:

var TestDemoFunc = Class.create();
TestDemoFunc.prototype = {
    initialize: function() {
    },
	returnSomething:function(sysId){
		gs.info('Inside Script Include');
		//process some logic using sysID
		return 'Hello';
	},
	executeSomething:function(){
		gs.info('Execute Something');
	},

    type: 'TestDemoFunc'
};

 

Then go the Business rule and click on Advanced tab, from there you can invoke the script include as shown below:

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

	// Add your code here
	//Exeute the script include and store the result
	var storedValue = new global.TestDemoFunc().returnSomething(current.sys_id);
	gs.info('Stored Value is:'+storedValue);
	//Just execute the script include
	new global.TestDemoFunc().executeSomething();
})(current, previous);

You can take the help of the current object and pass it to your function in the script include. Attaching the screenshots for your reference. sc_demo.JPGBR_demo.JPG

Kindly mark my response as helpful if it helped you and let me know if you have any questions further.

Thanks,

Mahesh.

View solution in original post

6 REPLIES 6

bitzalini6
Tera Contributor

Hi Prashanthi Sath,

Are you sure that the Script Include is written correctly? Could you share a screenshot of the Script Include as well? It might not be defined as a function correctly.

Best regards!



bitzalini6
Tera Contributor

Hi Prashanthi Sath,

Are you sure that the Script Include is written correctly? Could you share a screenshot of the Script Include as well? It might not be defined as a function correctly.

Best regards,

Jitendra Diwak1
Kilo Sage

Hi @PRASHANTHI SATH,

 

could you please share the script include screenshot? And a bit more explain the requirement.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.

Ankur Bawiskar
Tera Patron
Tera Patron

@PRASHANTHI SATH 

are you sure line 5 is not breaking?

line 7 which calls the function is correct.

share the complete script include code and the config screenshot

If my response helped please mark it correct and close the thread so that it benefits future readers.

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