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

matthewch1
Tera Expert

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