Call a Function¶
Overview¶
You can call a function from other parts of your Realm app or from a connected client application.
Usage¶
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; };
Call from Another Function¶
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); };
Call from a JSON Expression¶
You can call a function from a Realm JSON Expression, including service rules, by using the
%function
operator:
{ "numGamesPlayed": { "%function": { "name": "sum", "arguments": [ "%%root.numWins", "%%root.numLosses" ] } } }
Call from a Client Application¶
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.