How to compare two dynamic values in conditional transformer

Table of Contents

Use Case

In most cases, you need to do some transformations or mapping if a property meets certain conditions. In order to achieve that, Alumio has Conditional Transformer, which allows you to compare the value of a property with a static value defined in the transformer.

Now, what if you need to compare dynamic values between two properties as a condition before doing some transformations or mapping? Alumio has a limitation where it doesn’t support parsing placeholders yet in the compared value.

As you can see above that Alumio will not compare values between property foo and bar as placeholders are not supported yet in the Value field.

What we can do is to define a new variable whose value is a result of comparison between the values of foo and bar using JMESPath. Then, we use the new variable in Conditional transformer and compare it with boolean True or False.

Steps to Follow

Let’s say you have the below entity data.

{
  "foo": true,
  "bar": true,
  "result": null
}

You need to set a value of result to "passed" if the value of foo equals to the value of bar.

First, you need to define a new variable namely, i.e., check and the value should be a boolean value as a result of comparing the value of foo and the value of bar (check if they are equal). You can use a Value setter with the help of JMESPath to do so.

Once you have the check property with the boolean value, you can freely do any comparison with it using Conditional Transformer and decide what to do afterward.

If you have the values of foo and bar are equal, then the result property will have a value of “passed” as defined in the Value Setter inside the Conditional Transformer.

Even further, you can do more complex comparison and use the value of the final “check” property to use as a condition in a Conditional Transformer.

The topic is very interesting. Is there the possibility of doing more advanced comparisons using this method?
In my case I wanted to check if a value from one key is included in an array. I used the following format, but I get an error.

&{parentIds[?contains(@, filter_parentId)]}

{
“id”: 5935,
“parentIds”: [
112,
5152,
4547,
4549,
7157,
6149,
5290
],
“language”: “en”,
“parentId”: 112
}

Hi Davide,

Welcome to the Alumio forum.

Could you please confirm whether you want to check whether the value of parentId exists in the array parentIds? If so, it is possible to use the JMESPath contains function, as shown below.

&{contains(parentIds, parentId)}

The value of the test key will be a boolean, as shown below.

{
  "id": 5935,
  "parentIds": [
    112,
    5152,
    4547,
    4549,
    7157,
    6149,
    5290
  ],
  "language": "en",
  "parentId": 1121,
  "test": false
}

You can then use the test property to do conditional transformations.

Feel free to let us know if this is not the case.

1 Like