Calling the ajax function from business rule

uma17
Tera Guru

Hi All,

I have a Business Rule from which I am trying to call a function "ajaxFunction_getDocumentBody", but its not getting invoked.

I tired calling it it many ways but its not.

Can anyone please let me know how to invoke "ajaxFunction_getDocumentBody" from business rule.

Thanks,

Uma

15 REPLIES 15

Chuck Tomasi
Tera Patron

Can you let us know what the requirement/objective of this is? It seems like we're focused on solving a technical issue when it may not be the proper solution. Ajax functions are typically called from the client side to retrieve information from the server. Business rules already run on the server side so I'm a bit confused how you came to the conclusion that Ajax was required from a business rule. Understanding what the requirement is would definitely help.


What Chuck is saying is true. I do not notice until now that you said you're doing a call from a business rule.



Having said that, from a business rule you can easily invoke a script include and it's given methods.



For instance...



There's a script include OOB which is called Discovery and it has a method that it's called warnMsg. You can then write from your business rule a script that invokes the script include Discovery on the following way...


var testGR = new Discovery;


testGR.warnMsg("Test this script");



Thanks,


Berny


Hello Chuck,



The purpose of calling Script include from Business rule is.



We have a requirement for generating the pdf with the signature embedded in it, we referred the OOB   "   Employment Verification " .



We template and signature image are stored in different tables , so refering to "Employment Verification" record producer they are using these script includes, so we have to invoke these script includes from our service portal so we thought we can invoke the these OOB script include copy from our Business rule.



Thanks,


Uma


kiruthika
Kilo Expert

Hi Uma,



Your code is correct.


Assign an answer to a variable and use it.




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




  // Add your code here


  var sicall = new hr_CaseAjax_amit();


var ans = sicall.getDocumentBody();


  gs.addInfoMessage(ans);




})(current, previous);


It will work.



Reagrds,


Kiruthika Bala


asit2
Kilo Expert

Hi Uma,



Below is the example of how to call a script include from business rule-



I wrote a before business rule -



Business rule-



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


                              //call script include


                              var ajaxobj=new script_include_called_from_business_rule();


                              var return_text=ajaxobj.TestFunction();


                              current.u_text_from_ajax=return_text;


                              //end call script include


})(current, previous);



Script include-



var script_include_called_from_business_rule = Class.create();


script_include_called_from_business_rule.prototype = Object.extendsObject(AbstractAjaxProcessor, {


TestFunction:function(){


                              return 'Hello';


},


type: 'script_include_called_from_business_rule'


});