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 Rhino script function or a Java method (depending on the language you are using).

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 Rhino script function or Java method called MyObject.myCustomAction() and will run it.

Rhino

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

Java

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

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

Examples:

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

Confirmation with custom fields

The action supports fields in the confirmation dialog:

On server side the action's method will receive the fields within a HashMap:

Rhino

MyObject.myCustomAction = function(params) {
    var myActionField = params!=null ? params.get("myActionField") : null;
    ...
}

Java

public String myCustomAction(HashMap<String,String> params) {
    String myActionField = params!=null ? params.get("myActionField") : null;
    ...
}

State transition with parameters

When the action is a transition, there is no method invoked but confirmation fields are passed thru an object's parameter named ActionFields. This parameters can be read in all common hooks during the state transition (validate / save / update).

Rhino

MyObject.postSave = function() {
    var params = this.geObjectParameter("ActionFields");
    var myActionField = params!=null ? params.get("myActionField") : null;
    ...
}

Java

public String postSave() {
    HashMap<String,String> params = (HashMap<String,String>)geObjectParameter("ActionFields");
    String myActionField = params!=null ? params.get("myActionField") : null;
    ...
}

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 client-side 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:

var MyObject = (function() {
    function test(inst, row_id) {
        return $ui.alert({ content: "Using instance " + inst + (row_id ? " and row ID " + row_id : "") });
    }
    return { myCustomAction: test };
})();

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).

The javascript statement also supports front parameter app, grant and obj when the server side substitution is not required:

javascript:return obj.getName().myCustomAction(obj.getInstanceName(), obj.getRowId())

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