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.

can we call script include from business rule?

snajaykumar1234
Kilo Expert

if its yes, give me a example...

thanks

sanjay

10 REPLIES 10

Karthik Reddy T
Kilo Sage

Hello Sanjay,



Refer the below thread may helpful to you.



Can we call a script include from a business rule



How to execute script include from business rule


How to call script include from business rule


Karthik Reddy T.
ServiceNow Commnunity MVP -2018 class.

lSurya 24
Giga Guru

Hello Sanjay,



Yes you can call script include from a business rule.



ex:


  1. function onAfter(current, previous) {  
  2.       var wsClient = new scriptincludenamehere();  
  3.       wsClient.process();  
  4.  
  5. }


Below links will be handy,


How to execute script include from business rule


Problem calling a Script Include from a Business Rule


Using Business rule to run script include in the background


parvinder2
Kilo Guru

Yes you can call.



BR :



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


 


  var obj = new SI name();


  SIname.functionname(current, previous);


})(current, previous);



use SI : SI name




var SI name= Class.create();


SI name.prototype = {


  initialize: function() {


  },



functionname: function(current, previous) {


          try {


                                                                                           


    }


      catch(e) {


                  gs.log(e.message);


  }



Please mark correct and helpful.



Regards,


Parvinder


snehabinani26
Tera Guru

Hi Sanjay,



To execute a script include from Br you just need to create an object of that script include(which is typically a class) and call the function of that script include with the object.



eg, script include - MyScript


function in the script incldue - myfunction()



in the Br just write


var x=new MyScript();


x.myfunction();