Calling the ajax function from business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2017 08:32 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 08:49 AM
This can be done by instantiating the AJAX Script Include and then overriding the getParameter function to be used with passed server parameters instead of HTTP request parameters sent from the client.
Suppose this is your AJAX class:
var ExampleAjax = Class.create();
ExampleAjax.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
echo: function() {
return 'You said: ' + this.getParameter('msg');
},
type: 'ExampleAjax'
});
You can use it on the server as follows:
var ea = new ExampleAjax();
ea.getParameter = function(paramName) {
return {
msg : "Hello World"
}[paramName];
}
gs.info(ea.echo()); // Prints "You said: Hello World"
For convenience, I've created a helper function, makeCallable, to make this even easier. See the function and example at my makeCallable gist