You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

Custom Schema Methods

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');

Search results for "Custom Schema Methods"

We could not find anything matching "Custom Schema Methods" in our documentation. Please rephrase your search.

You can also ask your questions in the Structr Google Group or create a free account in the Structr Support Portal.
Click here to send feedback to the Structr team.