I have 2 field in the input, one is primary_language & the other is secondary_language. I have a case where I have to lookup values present in these two fields and then return a specific value according to the table. For example If primary language is English & secondary language is null then English will be the output & if primary language is Spanish & secondary is Sign then put None in the output & so on. Can one tell how we can perform this in dataweave in mulesoft.
Asked
Active
Viewed 5,297 times
2 Answers
1
Do you really have some more dynamic logic or its just the two conditions you mentioned above?
you can use when/otherwise or call another flow to get the value.
%dw 1.0
%output application/java
---
{
language: 'English' when (payload.primary == 'English' and payload.secondary is :null)
otherwise ('None' when payload.primary == 'Spanish' and payload.secondary == 'Sign'
otherwise ''
),
language2: lookup("testFlow",payload)
}

Manik Magar
- 1,403
- 2
- 10
- 20
-
Hi @Manik Magar, I used another approach for this so not sure if this will work. I have another similar question, I am creating an xml in output in one Dataweave of which i need to lookup a value for a field say "Status" from another flow & output of dataweave (by declaring variable in this data weave to convert input status in some fixed format). I am putting fund-status: lookup("Test",payload) & in a "Test" flow I am putting this %output application/java %var STATUS = {"Com" : "COMPLETE","Ref" : "REFUND"} --- {fund-status: flowVars.XYZ.status}. But i get Cannot coerce object to string. – Hemant Jun 07 '16 at 05:13
-
@Hemant, if this is different question, could you please open a new question and add config's if possible, so that we can help. Thanks. – Manik Magar Jun 07 '16 at 15:58
0
I would recommend to create another flow which performs this lookup for you (potentially you could do a database call, or something else like a groovy script), and store your values and what you expect to get returned based on those values.
https://docs.mulesoft.com/mule-user-guide/v/3.7/dataweave-reference-documentation#expressions-that-call-external-flows covers this concept a little bit, but the general idea is the following:
language: lookup("myLookupFlow", payload)
Then, all you need to do is query your dataset based on primary and secondary, and you will get your "transformed" value back.

Alan Kay
- 655
- 1
- 5
- 7