Reading Dynamic Values from a Property file in Dataweave 2.0 (Mule 4)

Author: Abhishek Bathwal


This Blog contains the Dataweave 2.0 code for reading a dynamic value from a property file based on the Input passed.

Step 1: Create a property file which contains the Abbreviation and Description for some defined Values.

Step 2: The property file needs to be configured in Global Elements:

Dataweave 2.0 Code:

%dw 2.0import * from dw::core::Stringsoutput application/json
fun lookupvalues(value, property) = if (value != null and upper(property) == ‘ABBRV’)substringBefore(p(value replace ” ” with “-“), ‘|’)else if (value != null and upper(property) == ‘DESC’)substringAfter(p(value replace ” ” with “-“), ‘|’)else ”—{ Value: lookupvalues(payload,’abbrv’), Description: lookupvalues(payload,’desc’)}


Output:{  “Value”: “RM”,  “Description”: “Runtime Manager”}

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.