0

We are migrating Mule 3 app to Mule 4 where we have encountered below MEL. Any inputs on how to convert it to DataWeave.

mel:prevProperties.get(payload.get("A1 - Roll Number")) == null ? prevProperties.put(payload.get("A1 - Roll Number"), payload.get("M7 - Detailed status")) : duplicateRecords.put(payload.get("A1 - Roll Number"),": Duplicate Name Found By ID")
aled
  • 21,330
  • 3
  • 27
  • 34
  • 1
    Please add some emore details like what is your input and what is expected output becasue in mule4 there is far better way to do something than in mule 3. – Anurag Sharma Feb 09 '22 at 11:12

1 Answers1

2

So this script can not be migrated as is to mule 4 as it uses side effects something that is not allowed in DW.

prevProperties.get(payload.get("A1 - Roll Number")) == null ?
        prevProperties.put(payload.get("A1 - Roll Number"), payload.get("M7 - Detailed status")) : 
        duplicateRecords.put(payload.get("A1 - Roll Number"),": Duplicate Name Found By ID")

So in order to map this semantically we need to get more context on your flow. To map syntactically the parts that can be mapped will be something like

if(prevProperties[payload["A1 - Roll Number"]] == null) 
    prevProperties ++ {(payload["A1 - Roll Number"]): payload["M7 - Detailed status"]}
else duplicateRecords ++ {(payload["A1 - Roll Number"]) : ": Duplicate Name Found By ID"}

And again this is not exactly the same as ++ doesn't modify but rather create a new instance.

machaval
  • 4,969
  • 14
  • 20