It is possible to perform actions within a message when an event occurs. These include performing a calculation, capturing location etc. To configure see the ‘Actions’ section under the ‘Extras’ tab in a Template.
Available events include:
|on change in value||when a field’s value is changed, eg entering text|
|on navigation||changing tabs or going to another card via a Link Command|
|after loading remote data||triggered when a remote load has successfully completed|
|after a message is created||triggered when a new message is created after default data has been set|
|after a message is replied to||triggered when a message is replied to after the data has been copied from the original message|
Available actions include:
|Capture location||attempts to get the current location and stores in the selected meta data|
|Reset default value||resets the selected fields to their defaults|
The functions should take a single argument that will be a JS object derived from the message data at the level the function is run. For example if the function is run at the root level then it will be all the message data. If the function is run within a list card item then it will only contain that items data. It should return a JS object with a data property that contains the values to be merged back into the current message data.
There are options for running JS function when the ‘done’ button is pressed to exit editing a list card item and to perform extra validation when sending a message or exiting a list card item. You may use this to set a complete flag for the item, as well as performing more complex validation, for example.
Set the content of the JS Functions text area, under the ‘Extras’ tab, with the content of the JS to compile. This can include supporting variables and functions along with the actual function to call from AMS.
When accessing JS values the property is set to the external label. For example a Date Item with external label start would be accessed in the JS function like msgData.start (assuming that ‘msgData’ is the name of the single argument in the function definition). The following are the data types for the values:
|Field||JS Data Type|
|Text, String or Text Box||String|
|Choice Group||Array of Strings|
|List||JS Object with values of selected list item as properties|
|List Card||Array of JS Objects (each object is a list card entry)|
An example of a simple time calculation:
An example of calculating a score based on answers to questions: