โ06-05-2021 05:23 PM
Hi,
I am trying to convert xm1 into xml2.
In order to that I have used XML Parser, Mapper,XML Formatter.
There is one logic, I need to create a segment only if value of a particular repeatable segment is either
jsonPath($, โ$Z_RDGD102.IDOC.DKA1[].PAR") is equal to โAFโ or โAGโ or โPCโ.
And part of output segment is like below:-
jsonPath($, "$Order.Data.Addresses[].Address[*]โ)
How do I achieve it, please let me know.
โ06-06-2021 08:01 AM
Hi @Sahil,
You can use mapping to do this. Here is an example:
jsonPath($, โ$Z_RDGD102.IDOC.DKA1[*].PARโ).map(x=>x == โAFโ || x == โAGโ || x == โPCโ).toString()
Or, if you have multiple PAR objects in DKA1, and at least one should match the condition, than you can go with this:
$Z_RDGD102.IDOC.DKA1.filter(x=> x.PAR == โAGโ || x.PAR == โAFโ || x.PAR == โPCโ).length>0
Regards,
Bojan
โ06-06-2021 08:30 AM
Hi,
I tried 1st option but I am getting below error:-
Failure: Unable to write to JSON-Path: $.Order.Data.Addresses, Reason: Expecting object or array for wildcard path, found: true,false,true,true,false,true, Resolution: Change the preceding path to refer to an object or array value
โ06-06-2021 08:46 AM
โ06-06-2021 01:23 PM
As I said @Sahil, if you have multiple PAR objects, you need to go with the second expression. The expression is a boolean, if only one of the repeatable segments is AF,AG or PC , than youโll have True.