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

bernyalvarado
Mega Sage

Hi uma, taking an official example from docs:



var ga = new GlideAjax('ajaxFunction_getDocumentBody');
ga
.addParam('sysparm_name', 'nameOftheFunctionwithinyourScriptInclude');
ga
.addParam('sysparm_parameteri1', "valueofParameter1");
ga
.getXML(HelloWorldParse);

function HelloWorldParse(response) {
 
var answer = response.responseXML.documentElement.getAttribute("answer");
  alert
(answer);


}



https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/script/server-scripting/referen...



Thanks,


Berny


Notice that the first line invokes the name of your script include, which is the same as the name of your Class within it.


The second line invokes the method within your script include. The parameter is called sysparm_name and the value is the MethodName


The third line defines a first parameter (in this example within name parameter1) followed by the value you want to pass in.



Thanks,


Berny


I hope this helps


srinivasthelu
Tera Guru

Hi Uma,



It might be getting called, but look for the lines that has something similar to this.getParameter... in your function.



If you have any of those, there is a high chance, you are running into exceptions on which javascript is not so good yet.



Comment everything and add only log statements, just to check that the function atleast gettting invoked (who knows, typos !!!! )