dataweave

Mapping from XML to CSV loop over values separated by underscore

[亡魂溺海] 提交于 2020-01-16 09:59:50
问题 <tXML> <Header> <Source>J1_RETAIL</Source> <Action_Type>Update</Action_Type> <Sequence_Number>0</Sequence_Number> <Batch_ID>4383352</Batch_ID> <Reference_ID>04381645</Reference_ID> <User_ID>SAP</User_ID> <Password>password</Password> <Message_Type>SAP_DO</Message_Type> <Company_ID>J1</Company_ID> <Msg_Locale>English (United States)</Msg_Locale> <Msg_Time_Zone>Eastern Standard Time</Msg_Time_Zone> <Version></Version> <Internal_Reference_ID></Internal_Reference_ID> <Internal_Date_Time_Stamp><

concatenate XML values using dataweave mule

一笑奈何 提交于 2020-01-16 06:41:50
问题 We have a scenario where we need to concatenate all XML node values to String. input XML <root> <line>1</line> <line>2</line> <line>3</line> <line>4</line> </root> Output to String 1234 Please let me know how can i achieve in form of String. Thanks in advance. 回答1: Referring DataWeave Reference Documentation at Reduce section: Transform %dw 1.0 %output application/json --- concat: ["a", "b", "c", "d"] reduce ($$ ++ $) Output { "concat": "abcd" } Therefore, you can try something like this:

How to pass Java object to a Java function in mule

醉酒当歌 提交于 2020-01-14 03:41:13
问题 I am trying to invoke a java function in mule.I converted the payload into the Object and passed it in the function. The name of the Java object created is req . The method validate accepts a Java Object Of type Example public HashMap<String, String> validate(Example req) {.......} Example class looks like this: Class Example{ String key1; String key2; String key3; } XML configuration looks like this : <java:new constructor="Example(java.lang.String,java.lang.String,java.lang.String)" doc

Ignore and log CSV row in DataWeave if condition is met

感情迁移 提交于 2020-01-14 02:56:09
问题 In DataWeave, is it possible to ignore a particular row in a CSV file if a condition is met. I'm transforming a file where some rows need to be ignored because a column has a value indicating a particular row shouldn't be mapped to the output. What I want to do in this scenario is skip that row, log (if possible) and then move on to mapping the next row. I've looked through the docs and the closest I've found to an answer is wrapping the mapping in a when otherwise clause. I can't find

Dataweave empty array input add default key:value

旧城冷巷雨未停 提交于 2020-01-07 02:55:11
问题 is there a way to map a http response which is in json array to another json map also considering default values i.e when it is empty map a default key pair? input { "key1": [] "key2":[x,y] } req output {"table":[{ "a-key1": "deafault-value", "a-key2": "x", "b-key2": "y" }] } 回答1: You can use default keyword only in case of null but for blank and empty array you can use something like %dw 1.0 %output application/json %function getDefault(inputdata, defaultvalue) inputdata when inputdata !=

How can i increment variable value inside function mapobject datawave 2.0?

房东的猫 提交于 2020-01-06 02:42:43
问题 How can i increment variable value inside mapobject(I do not want to use index) in mule4 datawave2.0? My Code: "Employees":{(inputData.*Employees.*Employee map{ "Employee": ($) mapObject(v,k) -> { ---Increment variable value here (k):updateReferenceId(v,($$)+1,v) } })} 回答1: You can increment values in the accumulator of a reduce operation, and you can then add these to the structured data plan f the output. There are some examples in the MuleSoft DataWeave training course flightsInput reduce

How to access the payload when implementing the validator interface?

☆樱花仙子☆ 提交于 2020-01-03 01:58:06
问题 I have to validate the incoming json payload and throw custom errors if the json is not valid. I tried implementing the validator interface as shown in the above image. But how should I access the payload now?In earlier versions the method accepted a mule event through which we could easily get the payload: public interface Validator { /** * Performs the validation and generates a * {@link ValidationResult} back. * * @param event the current {@link MuleEvent} * @return a {@link

Lookup list of Maps variable in data weave script

社会主义新天地 提交于 2019-12-25 09:15:31
问题 I have a list of maps (listOfMapsObject) like below [ { "Id" : "1234", "Value" : "Text1" }, { "Id" : "1235", "Value" : "Text2" } ] I would like access "Value" field for a given Id in dataweave script. For example: For Id = 1234, Text1 should be returned. %dw 1.0 %output application/json %var listOfMapsObject = flowVars.listOfMaps --- payload map { "key" : $.key, "data" : lookup Value field in listOfMapsObject by given key } 回答1: Approch suggested by @'sulthony h' is fine but it will end up in

how to merge two Json based on key value in Mule

落爺英雄遲暮 提交于 2019-12-25 08:18:02
问题 Hi I have a 1 json as below "first": [ { "projectid": "15", "approval_status": "A" }, { "projectid": "24", "approval_status": "A" } ]} The next payload is stores in a flowVariable { "Second": [ { "projectid": "15", "total": "123", "updated": "yes" }, { "projectid": "24", "total": "123", "updated": "yes" }]} Am using datawevae to merge these payload but its not giving expected result my expected value is { "Result": [ { "projectid": "15", "total": "123", "approval_status": "A" }, { "projectid"

Merge two json payload with dataweave

喜你入骨 提交于 2019-12-25 08:06:32
问题 I have a Mule flow that calls two REST API's resulting in two json list payloads. I need to obtain a merged json list from these two payloads. I managed to achieve this with a scatter-gather flow with a custom aggregator strategy. However the code I had to write for this looks rather messy and it's slow. Is there any way to achieve this using dataweave?` input Json list 1: [{ "ID": "1", "firstName": "JANE""familyName": "DOE", "Entities": [{ "ID": "515785", "name": "UNKOWN UNITED", "callSign":