Call a Function

You can call a function from other parts of your Realm app or from a connected client application.

The examples in this section demonstrate calling a simple function named sum that takes two arguments, adds them, and returns the result:

// sum: adds two numbers
exports = function(a, b) {
return a + b;

You can call a function from another function, including incoming webhooks and triggers, by accessing function context with the context.functions global variable:

For additional information, see the Function Context reference page.

// difference: subtracts b from a using the sum function
exports = function(a, b) {
return context.functions.execute("sum", a, -1 * b);

You can call a function from a Realm JSON Expression, including service rules, by using the %function operator:

"numGamesPlayed": {
"%function": {
"name": "sum",
"arguments": [

You can call a function from client applications that are connected with a Client SDK or over the wire protocol.

To execute a function from the iOS Client SDK, see the iOS SDK guide for calling a function.

Give Feedback