cancel
Showing results for 
Search instead for 
Did you mean: 

How to find if the entity exists in an array or not

arvindnsn
Contributor

Hello,

   I have a scenario where i use the Gate Snap and the output of the snap would be a empty array or list of entities in the array as shown below.

If the array is empty, it would give output with "original" values ( i need this to take the values in the forward snaps) and if the array is not empty, it would have the below output. 

One of the entity in the array is "Name" and i am trying to use "hasPath" function to check if the array is empty or not but in vain.

Since "Original" values are coming along, even if the array is empty, it is giving 1 as an output if i use the "length" function.

I would like to find a solution to check if the array is empty or not by checking the existence of one of the entities that the array returns.

arvindnsn_0-1722920633664.png

 

Thanks 

Aravind N 

1 ACCEPTED SOLUTION

Aleksandar_A
Contributor III

Hello @arvindnsn,

You can filter the array that comes out from the Gate Snap using the following expression:

$input0.filter(x => x.hasPath("Name")).length > 0

Based on the result of this, if no element has Name field it will return false, otherwise it will return true.

Attached below is a sample pipeline that you can review.

Please let me know if this helps you.

Regards,

Aleksandar.

View solution in original post

2 REPLIES 2

Aleksandar_A
Contributor III

Hello @arvindnsn,

You can filter the array that comes out from the Gate Snap using the following expression:

$input0.filter(x => x.hasPath("Name")).length > 0

Based on the result of this, if no element has Name field it will return false, otherwise it will return true.

Attached below is a sample pipeline that you can review.

Please let me know if this helps you.

Regards,

Aleksandar.

Hello @Aleksandar_A,

   That worked perfectly. Thank you very much!