Skip to content

Message Handler Scripts

As described in section Groovy Scripts, these are scripts executed whenever IntegrationM receives a new message. In the local repository they are stored at /integrationm/scripts, and in the server machine they are deplyed at /etc/integrationm/scripts.

In this section we will describe the arguments passed to every script, and we will give a few examples.

Script Argument

A message script handler will receive an instance of a RecordmMsg java object with the information about the event that generated it. The message has the following format:

{
	 "product": "recordm",
	 "user": "admin",
	 "action": "add",
	 "type": "Employee",
	 "instance": {...}
}

A complete list of the methods and operations supported by this message argument can be found at RecordmMsg page.

product

It is the name of the server which generated this event. The supported string values are:

  • recordm
  • confm

These values indicate that the messages come from the the servers RecordM and DeviceM respectively.

user

It is the user that performed the action which generated this message. For example, when a user creates a record on the frontend application, this field will have the string username of the user.

It only allows the username of the users registered in UserM.

action

The action field indicates the action performed on the server that generated the event. The supported string values are:

  • add
  • update
  • delete

type

It is the name of the definition on RecordM upon which the operation was made.

instance

It is a Java object which represent the RecordM record that was created/deleted/updated.

Example

the file: /integrationm/scripts/changeDate.groovy

if (msg.type != "Countries Series" || msg.product != "recordm" || msg.action != "add") return

log.info("Updating the date if necessary")
long date = msg.value("Year",Long)
long now = System.currentTimeMillis()

def response;
if (date > now) {
    def instanceId = msg.getId()
    response = recordm.update("Countries Series",instanceId,["Year":now])
    log.info("THE RESULT OF THE UPDATE IS: ${response.ok()}")
}

Question to the reader: What is the code doing ?

The following image shows the log of the script, which can be seen using the following commands:

ssh <server_name>@cultofbits.com
im-log

Figure 1. Log output. log