Showing results for 
Search instead for 
Did you mean: 

Expression help

New Contributor II

I am working on a new pipeline for syncing some data.  as part of that sync I want to compare my new data against the data in the target system so I don't update any data that is unchanged.  in order to do this I have written an expression to do a lookup on some types in the system to ensure that I'm only comparing things of the same type (ex legal names with legal names).  

I've written the following expression:


jsonPath($, "persons.old[*].names[*]").indexOf(jsonPath($, "valcodes['person-name-types'][*]").filter((value)=>value.code=='LEGAL')[0].id) != -1 ?jsonPath($, "[0].firstName") != jsonPath($, "persons.old[*].names[jsonPath($, "persons.old[*].names[*]").indexOf(jsonPath($, "valcodes['person-name-types'][*]").filter((value)=>value.code=='LEGAL')[0].id)].firstName"): false


which is supposed to get the index of the proper name in the document and then if it finds the type exists in the list it's supposed to check if the old name of that type is different from the new name of that type.  Where I'm struggling is with the index check, the expression 


jsonPath($, "persons.old[*].names[*]").indexOf(jsonPath($, "valcodes['person-name-types'][*]").filter((value)=>value.code=='LEGAL')[0].id)


when run alone returns an index for me generally a 0 or 1, which I was hoping to use to get the proper name item in the list, but when I attempt to add the lookup in place of the * in names[*]  I get the error:


Expression parsing failed near -- nPath($, " >> persons << .colleagu (Reason: Mismatched input 'jsonPath' at line 1:273. Expecting one of: {OctNumber, HexNumber, Float, Digit, QuotedString, NonTerminatedString, Regex, 'match', '[', '{', '(', 'true', 'false', 'function', 'null', 'NaN', 'Infinity', Id, '@'}; Resolution: Please check expression syntax)
I assume this is due to me attempting to use a jsonPath inside a jsonPath, but I'm not entirely sure what to do about it.  I'll also note, this sequence does work if I hard code the ID I'm attempting to search for using ? inside the jsonPath statement, however I really want to avoid doing that as the ID I'm looking for will vary between dev test and production

New Contributor II

Since I didn't add it before, this is an example of an expression that works, but it has the key I need hard coded I just need to find a way to dynamically get that key from my valcode table instead of having to hard code it


jsonPath($, "persons.old[*].names[*]").indexOf(jsonPath($, "valcodes['person-name-types'][*]").filter((value)=>value.code=='LEGAL')[0].id) != -1 ?jsonPath($, "[0].firstName") != jsonPath($, "persons.old[*].names[?( == '55110e25-2ec5-421f-82d5-cc98451a019e')].firstName").toString(): false


Contributor III

Hello @maddog0,

I'm not completely sure that I fully understand your requirement, but it might be worth taking look at the Join Snap or Diff Snap .

Let me know if this was of any help.