Reading Dynamic Values from a Property File in Dataweave 2.0 (Mule 4)
This short article contains the Dataweave 2.0 code for reading a dynamic value from a property file based on the input passed.
Join the DZone community and get the full member experience.
Join For FreeThis short article contains the Dataweave 2.0 code for reading a dynamic value from a property file based on the input passed.
Created a property file that contains the Abbreviation
and Description
for some defined values.
The property file needs to be configured in Global Elements:
Dataweave 2.0 Code
%dw 2.0
import * from dw::core::Strings
output 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')
}
Testing
xxxxxxxxxx
Input:
"RuntimeManager"
Output:
{
"Value": "RM",
"Description": "Runtime Manager"
}
Published at DZone with permission of Abhishek Bathwal. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments