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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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)
}
回答2:
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.