Custom action examples

Please refer to basic code examples document for naming conventions and logging strategies.

Server-side custom action

A server-side action corresponds to an action with a value in the method field.

This method field contains the name of a server-side script function.

For instance if you set myCustomAction as action method and if you grant this action to the MyObject business object, the platform will look for the server-side script function MyObject.myCustomAction() and will run it.

MyObject.myCustomAction = function() {
    var rowId = this.getRowId();
    return Message.formatSimpleInfo("Using instance " + this.getInstanceName() + (!Tool.isEmpty(rowId) ? " and row ID " + rowId : ""));
}

On responsive UI (using ajax services) the action can return:

Examples:

return Message.formatSimpleError("It is not permitted"); return this.javascript("$ui.displayForm(null, 'myObject', 'rowId', {nav:'add'})"); return this.redirect(HTMLTool.getFormURL("myObject", "the_ajax_myObject", rowId, "nav=add"));

Note: These server-side custom actions are available from the webservices APIs

Client-side custom action

A client-side action corresponds to an action with a value in the URL field.

Plain URL

When URL contains a plain URL (that can be either absolute or relative), the platform UI will call this URL appending the object, inst and row_id URL parameters.

JavaScript statement pseudo-URL

When URL contains a JavaScript statement pseudo-URL (starting with javascript:), the platform will run this JavaScript statement after having substituted the [object], [inst] and [row_id] tags.

For instance, let's say you have created the default client JavaScript resources SCRIPT resource for your MyObject business object like this:

MyObject = (function MyObject($) {
    function test(inst, row_id) {
        return Simplicite.UI.popup({ content: "Using instance " + inst + (row_id ? " and row ID " + row_id : "") });
    }

    return { myCustomAction: test };
})(jQuery);

Then you can configure a custom action for MyObject to call this myCustomAction function with this value in the URL field:

javascript:return [object].myCustomAction('[inst]', [row_id])

Attention, due to the way the UI runs the JavaScript statement, you must only use simple quotes ' in it (this limitation does not apply to the content of the SCRIPT resource).

Note: These client-side custom actions are not available from the webservices APIs.