Custom Lookup in dataweave

房东的猫 提交于 2019-12-25 04:40:29

问题


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.



来源:https://stackoverflow.com/questions/35573711/custom-lookup-in-dataweave

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!