'MEL to DataWeave conversion

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")


Solution 1:[1]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 machaval