1.6.0
The Stryke Library provides access to execution data and methods that can be used by the scripts to interact with Stryke. All scripts will have a global instance of the stryke library ready to use. This instance can be accessed via the global variable "stryke". The stryke library variable is read-only, its methods and properties cannot be modified.
All execution paths within a script must be resolved by calling either stryke.resolve or stryke.error. Failing to resolve a path that is executed will result in the script timing out.
(UserInfo)
: The details of the user that is executing the script.
(ExecutionData)
: An object to access data specific to this script execution (example: the trigger record, or request payload).
Creates a new record with the given data. This function takes an optional callback. If a callback is provided, it will be called when the create operation completes. The callback has two arguments: the first parameter is reserved for any errors that may have occurred, if no errors occurred the parameter will be null, the second parameter will contain the response's data. If no callback is provided, this function will return a promise, which will be resolved when the create operation completes or rejected if any errors occur.
Executes a query to find a set of records. This function accepts a GraphQL query (it supports Stryke's query filters) but returns directly the array of records found, instead of the GraphQL standard format like with the 'query' function. If the query set as parameter contains more than one query statements, the result will be the same as the one returned by the 'query' function that follows the GraphQL standard.
In case of an error, this function will throw.
(string)
the GraphQl query string
any
:
an array containing the records retrieved by this query.
Executes a query to find a single record. This function accepts a GraphQL query (it supports Stryke's query filters) that retrieves a single record. It returns that record directly, instead of the GraphQL standard format like with the 'query' function. If the result of the query contains more than one record this function will throw. Note that this function can only execute one query. If you wish to execute multiple queries in the same request use the query or find functions instead. Access control is applied to the result returned.
In case of an error, this function will throw.
(string)
the GraphQl query string
any
:
the record retrieved by this query.
Executes a GraphQl query on the app instance's data. This function takes an optional callback. If a callback is provided, it will be called when the query completes. The callback has two arguments: the first parameter is reserved for any errors that may have occurred, if no errors occurred the parameter will be null, the second parameter will contain the response's data. If no callback is provided, this function will return a promise, which will be resolved when the query completes or rejected if any errors occur.
This method returns a GraphQL result in the GraphQL standard format. https://github.com/graphql/graphql-spec/blob/master/spec/Section%207%20--%20Response.md
The response object has the following structure: { data: { MyQueryName1: [ {}, {}, {} ], MyQueryName2: [ {}, {}, {} ], } errors: [ { message: "", locations: []}, { message: "", locations: []} ] }
Data contains the result of the queries submitted. Accessing the result of a specific query is done as follows:
queryResult.data.MyQueryName1[0]
Errors conttains any error that may have occurred during the query.
(string)
the GraphQl query string
(boolean)
optional parameter to instruct Stryke to run this query with or without
applying access control. If set to true the query result will be filtered
based on what the executing user has access right to view. If set to false
the result of the query will not be filtered and all records will be returned.
If not specified, the default value is true.
(function)
an optional callback function. If none is provided this function will return
a promise.
any
:
a GraphQL query result.
Resolves the execution of a script with an optional value. This method must be called at the end of a script. If a script has any asynchronous callbacks, the resolve method should be called at the end of the callback chain. No further instructions from the script are executed after the resolve method is called.
If data needs to be returned by the script, it should be passed as the argument of the resolve method.
(any)
an optional return value of the script.
Updates a record with the given id, and the supplied data. This function takes an optional callback. If a callback is provided, it will be called when the update operation completes. The callback has two arguments: the first parameter is reserved for any errors that may have occurred, if no errors occurred the parameter will be null, the second parameter will contain the response's data. If no callback is provided, this function will return a promise, which will be resolved when the update operation completes or rejected if any errors occur.
The ExecutionData object holds execution data, which can be used by scripts at run time.
For example, the execution context can hold the record in context for the current execution, or the old and new values of a record in a trigger execution.As with all members of the stryke global variable, stryke.data (which holds the ExecutionData instance for each execution) is read-only. If you wish to modify the values within an object held inside stryke.data you need to make a copy of the object first. Example:
(object)
: The record in context for this script execution. This is the record from which an action was executed.
For example if the action is of type "button", record will contain the record on which the button was clicked.
(object)
: Any data that was passed as payload (ie the body of the HTTP request) to the original script or
action execution request. This can be used to pass request specific arguments to the script being executed.
The payload must be in valid JSON format.
(Array<Object>)
: Set when executing a create or update trigger script. This property holds an array containing the
records that are being created or updated (with the new values that will be applied by the update operation).
If only a single record is being created or updated, the array will only contain 1 element. 'new' is not set in delete triggers.
(Array<Object>)
: Set when executing an update or delete trigger script. This property holds an array containing the
records that are being updated (with the old values that will be overridden by the update operation) or deleted.
If only a single record is being updated or deleted, the array will only contain 1 element. 'old' is not set in create triggers.
(object)
: Deprecated - Set when executing an update or delete trigger script, it holds the single record or
first record in the array of records that are being updated or deleted. This is equivalent to the first entry of the 'old' array.
Important: Use 'new' instead of this property and implement your triggers following a bulk approach.
(object)
: Deprecated - Set when executing a create or update trigger script, it holds the single record or
first record in the array of records that are being created or updated. This is equivalent to the first entry of the 'new' array.
Important: Use 'new' instead of this property and implement your triggers following a bulk approach.
A model containing information about the user that is executing a script.