I have a payload as list of maps and another flow variable as map.
I wanted to add flow variable to payload list. I tried using this expression #[payload.addAll(flowVars['entitlement'])]in expression component. But it sets the payload to boolean value true.
Use expression component like
<expression-component doc:name="Expression"><![CDATA[payload.addAll(flowVars['entitlement'])]]></expression-component>
Hope this helps.
Try using Set Payload transformer.
and add
[payload.addAll(flowVars['entitlement']) as value.
You set the payload as the value returned by addAll(). It's like doing payload = payload.addAll(flowVars['entitlement']) in Java addAll() returns a boolean, that's why your payload becomes true.
You can use instead:
#[payload.addAll(flowVars['entitlement']); payload)
This will perform your addAll() operation on your payload and then return this modified payload afterward. ; allow your to perform multiple expressions in MEL
You can use dataweave transform component and add the elements in various ways like using the ++ operator or use map operator to change the structure as per your requirements.
Related
I have Observable on which i apply firstOrError() operator which return a Single<T>
Same i want to convert into Kotlin Flow. I want there must be some mechanism which return a flow with 1st item or error.
Do you have any idea on this how i can achieve that?
To convert Observable into Flow, you can use asFlow from kotlinx.coroutineslibrary.
Note that there is no way to convert Single into Flow because those are two incompatible types (single-value vs stream). But you can convert your Observable into Flow with asFlow first and then instead of firstOrError() use first().
What is the difference between reading the properties from payload. for example there is a property in the payload which is named as con_id. when i read this property like this #[payload.con_id] then it is coming as null. where as #[payload.'con_id'] is returning the value.
few other notations which i know of is #[payload['con_id']] or #[json:con_id]
which one should be used at which scenario? if there are any special cases to use any specific notation then please let me know the scenario also.
Also, what is the common notation that has to be used from a mule soft platform supported point of view.
In Mule 3 any of those syntax are valid. Except the json: evaluator is for querying json documents where as the others are for querying maps/objects. Also the json: evaluator is deprecated in Mule 3 in favor of transforming to a map and using the MEL expressions below.
payload.property
payload.'property'
payload['property']
The reason the first fails in your case, is beacaue of the special character '_'. The underscore forces the field name to be wrapped in quotes.
Typically the . notation is preferred over the [''] as its shorter for accessing map fields. And then simply wrap property names in '' for any fields with special chars.
Note in Mule 4, you don't need to transform to a map/object first. Dataweave expression replace MEL as the expression language and allow you to directly query json or any type of payload without transforming to a map first.
I'm trying to access a FlowVar name dynamically in DataWeave.
For example:
I have a flowVars named taxInfo123. This is a linked list and my applicant.ApplicantID = 123
In my dataweave, I want to access this dynamically. Something like the following:
"TaxInfo": flowVars.'taxInfo'+applicant.ApplicantID map ((taxIdentificationDetail , indexOfTaxIdentificationDetail) -> {
This obviously doesn't work, and I'm hoping this is possible and I just need the correct syntax.
If you need to dynamically create the variable name, you can use the flowVars[key] syntax instead of the flowVars.key syntax. In your scenario:
"TaxInfo": flowVars[('taxInfo' ++ (flowVars.applicant.ApplicantID as :string))]
I assumed applicant was also a flowVar but you could just as easily use payload.applicant.ApplicantID or whatever your situation calls for. I also assumed it was a number so I had to cast it as a string.
When you use this syntax you want to make sure you wrap the key expression in parenthesis so it is evaluated first and then the flowVar is resolved.
So to summarize:
If you know the variable name is 'taxInfo123' -
flowVars.taxInfo123 or flowVars[taxInfo123] are both valid
If you need to create the variable name dynamically -
flowVars[(expression)]
Hope that helps!
Forming the variable name needs append operator like ++. Please go through the MuleSoft documentation for Dataweave operators to get better understanding of how much flexiblity is possible in Dataweave.
https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-operators
I want to extract my payload's class name in a MUnit assert so I can verify the payload is always of the correct type. I've tried 2 MEL expressions, but both return null in the MEL expression evaluator. The funny thing is that if I remove the .name part of the expression then I see a key called "name" with the value that I need. Any ideas?
payload.class.name
message.dataType.type.name
One way is: #[payload.getClass().getSimpleName()]
Is there a way to pass null parameter to sql query using DBReport mediator?
I get empty value for my soap property and WSO2 fails.
If its is null use filter mediator to check the null and then use dbreport mediator.