Skip to main content
Version: 4.55

Event Parameters

Events in mos. are similar to functions or methods in other languages. It is possible to pass data to the event in form of parameters in order to reuse an event. In addition, some actions can fire events if the action was successful or an error occurred. In these cases, it is possible to access information about this success or error in the parameters.

Simple passing of parameters when firing an event

To fire an event, the fireEvent action can be used. The minimal call looks like this:

{
"type": "fireEvent",
"params": {
"eventType": "<the event name>"
}
}

To add parameters to this event, it is possible to add the eventParams field:

{
"type": "fireEvent",
"params": {
"eventType": "<the event name>",
"eventParams": {
"firstStringValue": "a text",
"secondNumberValue": 42
}
}
}

Using queries when firing an event

It is possible to fire an event with data from the database as parameters. This can be done with the following configuration:

{
"type": "fireEvent",
"params": {
"eventType": "<the event name>",
"table": "<table with the query>",
"query": "<name of the query>",
"queryMode": "single|all",
"queryParams": [
"<parameter for the query; this is optional>"
],
"template": "<name of the template to be applied to the query result>"
}
}
caution

With "queryMode": "all", the event will be fired for each row of the query result.

Using event parameters inside the event

The values of the event parameters can be generally used like data within a template. If no other delimiters are set, the default delimiters {{ and }} can be used. Inside global events (in the ./event directory) this is fine. When defining events inside of views, custom delimiters are needed, as the default delimiters are replaced when the view is created. This can be done with the fields leadingDelimiter and trailingDelimiter.

{
"type": "<the event name>",
"leadingDelimiter": "{<",
"trailingDelimiter": ">}",
"actions": [
{
"type": "showMessage",
"params": {
"text": "The parameter was {<firstStringValue>}"
}
}
]
}

Interaction between event parameters and action results

Event parameters are like a dictionary of keys and corresponding values. Actions with onSuccess and onError parameters can add or modify values in this dictionary. This happens when the type (onSuccessType/onErrorType) is set to return.

Example 1 - adding

Event parameters before:

{
"oldValue": "I am your king."
}

Action:

{
"type": "request",
"params": {
...,
"onSuccessType": "return",
"onSuccess": "requestResult"
}
}

Event parameters after:

{
"oldValue": "I am your king.",
"requestResult": {
"statusCode": 200,
"headers": {},
"response": {
"answer": "Well, I didn't vote for you."
}
}
}

Example 2 - replacing

Event parameters before:

{
"oldValue": "I am your king.",
"secondValue": "Be quiet!"
}

Action:

{
"type": "request",
"params": {
...,
"onSuccessType": "return",
"onSuccess": "secondValue"
}
}

Event parameters after:

{
"oldValue": "I am your king.",
"secondValue": {
"statusCode": 200,
"headers": {},
"response": {
"addition": "I didn't vote for you."
}
}
}