Skip to main content Skip to footer

Search Crosser Knowledge Base

Data mapping with the Template modules

Mapping data is usually done with the Property Mapper or Data Mapper modules, which supports the common mappings: renaming, change hierarchies and add/remove properties. Sometimes, especially when you need to create a complex message structure with lots of static data/hierarchies, it can be difficult to see the end result when using these modules. In these situations the ‘Template’ modules can be a better alternative.

With these modules you write the whole message structure as text, JSON in the case of the Message Template module and any text with the Text Template module. Using template syntax: {msgProperty} you can insert dynamic values from your Flow anywhere in the message structure. The difference between these two modules is that the Message Template module requires JSON syntax and will output a Flow message that can be processed in other modules. The Text Template module will output a text string. If you just want to create e.g. a JSON or XML message and send it to an external system the Text Template  module is the best choice. If you need to process the message before it is being delivered the Message Template module is the best choice. Then you can use the JSON or XML modules to convert the message to the corresponding text representations just before the output module.

Let’s take a look at an example template:

{
  "Factory": {site.name},
  "Line": "Packaging",
  "Asset": {site.machines[0].name},
  "Measurements": [
    {
      "Source": {data[0].name},
      "Value": {data[0].value},
      "Unit": "degC"
    },
    {
      "Source": {data[1].name},
      "Value": {data[1].value},
      "Unit": "psi"
    }
  ]
}

If we then send the following message to a template module with the above template:

{
  "data": [
    {
      "name": "temperature",
      "value": 25.2
    },
    {
      "name": "pressure",
      "value": 101.9
    }
  ],
  "site": {
    "machines": [
      {"name": "wrapper"},
      {"name": "printer"}
    ],
    "name": "factory1"
  }
}

We will get the following result from the template module:

{
  "Asset": "wrapper",
  "Factory": "factory1",
  "Line": "Packaging",
  "Measurements": [
    {
      "Source": "temperature",
      "Unit": "degC",
      "Value": 25.2
    },
    {
      "Source": "pressure",
      "Unit": "psi",
      "Value": 101.9
    }
  ]
}

About the author

Goran Appelquist (Ph.D) | CTO

Göran has 20 years experience in leading technology teams. He’s the lead architect of our end-to-end solution and is extremely focused in securing the lowest possible Total Cost of Ownership for our customers.

"Hidden Lifecycle (employee) cost can account for 5-10 times the purchase price of software. Our goal is to offer a solution that automates and removes most of the tasks that is costly over the lifecycle.

My career started in the academic world where I got a PhD in physics by researching large scale data acquisition systems for physics experiments, such as the LHC at CERN. After leaving academia I have been working in several tech startups in different management positions over the last 20 years.

In most of these positions I have stood with one foot in the R&D team and another in the product/business teams. My passion is learning new technologies, use it to develop innovative products and explain the solutions to end users, technical or non-technical."