Forum Discussion

arvindnsn's avatar
arvindnsn
Contributor
12 months ago
Solved

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

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.

 

Thanks 

Aravind N 

  • @Charles,
    Like Patrick, I was also thinking Velocity (VTL) as a solution, but as I tried to solution your original post, the Workday namespace convention in the property names adds some complexity. I don’t know if Velocity beats the null-safe mapper for your particular use case, but it can be good info for your tool belt in the future.

    The kind of ugly solution I came up with (in a one-liner) is:

    [
        {
           "output" : #set ($pd = $['wd:Project_Data']) #set ($ed = $pd['wd:End_Date']) #if (${ed}) ${ed} #else null #end
        }
    ]
    

    I’m not well versed in VTL, so there’s likely something a little cleaner than the above.

2 Replies

  • Ganesh's avatar
    Ganesh
    New Contributor II

    Hi,
    You can try Array.toString() function if its an array type or use string.replaceAll() function to achieve this.

  • ronmwhite's avatar
    ronmwhite
    New Contributor II

    It is hard to tell by what has been posted here, but, perhaps you need a JSON Splitter. At the right JSON path, you should get the unique GUID values required downstream. Feel free to ping me if you need any assistance. Thanks.

  • Kulashekharan's avatar
    Kulashekharan
    New Contributor II

    Use array.join(“,”) or array.toString() to achieve what you asked for. Join will allow you to change the delimiter. Keep in mind This returns one string value