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’)} |
Testing:
Input:“RuntimeManager” Output:{ “Value”: “RM”, “Description”: “Runtime Manager”} |