Forum Discussion

Igor_Bozhinovsk's avatar
Igor_Bozhinovsk
New Contributor III
3 years ago

Check if field inside array has value and route the output

[
{
“items”: [
{
“test”: " ",
“id”: 1
},
{
“test”: “test”,
“id”: 2
}
]
}
]
Currently we have an array like this , we need to route the output from the Router based on the test field , if there is a value the output should go to the upper branch if there is not value for the test field the output should go to the lower branch.

Is there any array method or something else that can be used to achive this ?

3 Replies

  • SpiroTaleski's avatar
    SpiroTaleski
    Valued Contributor

    @Igor_Bozhinovski

    The simplest way to do the routing is by splitting the array using the JSON Splitter Snap, and then in the Router Snap add the logic where you will route the records based on the “test” field(if it is empty or not).

    BR,
    Spiro Taleski

    • Igor_Bozhinovsk's avatar
      Igor_Bozhinovsk
      New Contributor III

      Thanks Spiro , but for now we need to check the element value inside in the array.

      Regards,
      Igor

  • SpiroTaleski's avatar
    SpiroTaleski
    Valued Contributor

    @Igor_Bozhinovski

    If you need to perform routing using the Router Snap(as you mentioned in the post), then you need the data to be flatten.

    You can split the data, perform routing and then revert back in array.

    Additionally, you can use the Map Function in order to go/iterate trough the array and check elements inside.

    BR,
    Spiro Taleski