Custom Schema Methods

Search
Feedback

Custom Schema Methods are arbitrarily-named StructrScript methods on a Custom Type. A custom schema method can be executed using a REST call to a special URL, or an Action Button. It is possible to return Nodes and Relationships, not arbitrary Objects (e.g. Strings,Integers,…), from custom schema methods.

Parameters

Any parameters supplied to the execution of a custom method, either via the HTTP request body or via direct parameter passing in server-side JavaScript execution, can be accessed in the method code using the retrieve() method.

Example Request
 POST /user/0a6a5363df334a638d06669f13975d06/doSomething
{ params: { key1: "value1", key2: value2 } }
Example Parameter Access
{
    var params = Structr.retrieve('params');
    [...]
}

Example

An EMail Example

A method named doSend on an entity called EMail entity can be executed using a POST request to the following URL.

/EMail/<uuid>/doSend

Direct Execution in JavaScript Context

In a serverside JavaScript context, a dynamic schema method can be executed directly on an instance object like this:

var instance = Structr.get('this');
instance.doSend( { name: 'test' } );

Note: Due to its implementation, if the method does not have any parameters, it must still be called with {} as parameter!

Schema methods on static (i.e. hard-coded Java types) are called slightly differently: Here the parameters are given directly and not through a JSON array.

var xmppClient = Structr.get('this');
xmppClient.doJoinChat('chatRoom@conference.server.org', 'nickname', 'password');

Graph-Browser

About this article
Last change 2017-03-27
Topics Structr 2.0