mapping payload with json object in dataweave
✔ Recommended Answer
Assuming that the input and table are arrays and that entries in the table are unique per CodeSap
the following script works, though the output is a bit different than expected because of the incomplete table provided:
%dw 2.0output application/jsonvar varTable=[{ "CodeSap": null, "Libelle": "", "CodeOT": 1 }, { "CodeSap": 0, "Libelle": "Elle a demandé un délai de paiement", "CodeOT": 1 }, { "CodeSap": 1, "Libelle": "Elle a des factures SATD", "CodeOT": 2 }, { "CodeSap": 2, "Libelle": "Elle a des factures remises à l’huissier", "CodeOT": 2 }]---payload map (item, index) -> { refSig: item.refSig, codeOt: (varTable filter (item.indSap == $.CodeSap))[0].CodeOT}
Output:
[ { "refSig": "0110443372", "codeOt": null }, { "refSig": "0000443942", "codeOt": 1 }, { "refSig": "0117243942", "codeOt": 1 }]
Source: stackoverflow.com
Answered By: aled
Comments
Post a Comment