How to special character selector field in dataweave? - mule

I am transforming a JSON input to XML output and I have a field with name Antigüedad with special character in it. I am following the below dataweave. XML is unable to generate this field. Can you please let me know where I am going wrong ?
%dw 1.0
%output application/xml skipNullOn="everywhere", encoding="UTF-8"
---
Acceptor #("Antigüedad": payload.Acceptor."Antigüedad")

I don't have sample data but this works for me:
%dw 1.0
%output application/xml skipNullOn="everywhere", encoding="UTF-8"
%var data = Acceptor #("Antigüedad": "Antigüedad"): {
}
---
Acceptor #("Antigüedad": data.Acceptor.#"Antigüedad"): {
}

Set
Content-type: application/json; charset=utf-8
in HTTP headers.

Related

Type mismatch for 'mapObject' operator in Mule 3.8.0 DataWeave that worked in 3.9.0

I built an API project that builds and sends a SOAP request to another service, based on parameters sent to the API. I inadvertently built the project in Mule 3.9.0 EE, when our production and dev Mule environments are 3.8.0 EE. The project works fine locally in 3.9.0, and it runs in 3.8.0 until it builds the request in Dataweave. It reports the following exception in 3.8.0:
Root Exception stack trace:
com.mulesoft.weave.engine.ast.dynamic.UnexpectedOperationTypesException: Type mismatch for 'mapObject' operator
found :array, :function
required :object, :function
I use two Dataweaves to build the request. The first builds the prompts used in the SOAP request from the parameters. The second builds the SOAP request and inserts the prompts.
The first Dataweave:
%dw 1.0
%output application/json
---
[flowVars.parameterMap mapObject (value, key)->{
PROMPT: {
PSQueryName: "",
UniquePromptName: key,
FieldValue: value
}
}]
The second Dataweave:
%dw 1.0
%output application/xml encoding="UTF-8"
%namespace SOAP-ENV http://schemas.xmlsoap.org/soap/envelope/
%namespace wsse http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
%namespace qas http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ_MSG.VERSION_1
%namespace qas1 http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ.VERSION_1
---
{
SOAP-ENV#Envelope: {
SOAP-ENV#Header: {
wsse#Security #(SOAP-ENV#mustUnderstand: "1"): {
wsse#UsernameToken: {
wsse#Username: "someUsername",
wsse#Password #(Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"): "somePassword"
}
}
},
SOAP-ENV#Body: {
qas#QAS_EXEQRY_SYNC_REQ_MSG: {
qas1#QAS_EXEQRY_SYNC_REQ: {
QueryName: flowVars.queryName,
isConnectedQuery: "N",
OwnerType: flowVars.queryType,
BlockSizeKB: 0,
MaxRow: 0,
OutResultType: "webrowset",
OutResultFormat: "nonfile",
PROMPTS: payload.*PROMPT mapObject {
PROMPT: {
PSQueryName: $.PSQueryName when $.PSQueryName != "" otherwise {},
UniquePromptName: $.UniquePromptName,
FieldValue: $.FieldValue
}
}
}
}
}
}
}
In 3.9.0, the Dataweave transformed the SOAP request perfectly. In 3.8.0, it has issue with the PROMPTS: payload.*PROMPT mapObject statement in the second DataWeave.
What changed in 3.9.0 that made this work properly?
What work around can I do to resolve this issue in 3.8.0?
I solved this on my own by combining the two Dataweaves, which separating the two proved to be unnecessary.
It does not answer what changes occurred in 3.9.0 that allowed it to work in the original project.
%dw 1.0
%output application/xml encoding="UTF-8"
%namespace SOAP-ENV http://schemas.xmlsoap.org/soap/envelope/
%namespace wsse http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
%namespace qas http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ_MSG.VERSION_1
%namespace qas1 http://xmlns.oracle.com/Enterprise/Tools/schemas/QAS_EXEQRY_SYNC_REQ.VERSION_1
---
{
SOAP-ENV#Envelope: {
SOAP-ENV#Header: {
wsse#Security #(SOAP-ENV#mustUnderstand: "1"): {
wsse#UsernameToken: {
wsse#Username: "someUser",
wsse#Password #(Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText"): "somePassword"
}
}
},
SOAP-ENV#Body: {
qas#QAS_EXEQRY_SYNC_REQ_MSG: {
qas1#QAS_EXEQRY_SYNC_REQ: {
QueryName: flowVars.queryName,
isConnectedQuery: "N",
OwnerType: flowVars.queryType,
BlockSizeKB: 0,
MaxRow: 0,
OutResultType: "webrowset",
OutResultFormat: "nonfile",
PROMPTS: flowVars.parameterMap mapObject (value, key)->{
PROMPT: {
PSQueryName: "",
UniquePromptName: key,
FieldValue: value
}
}
}
}
}
}
}

Mule Dataweave: How to dynamically map HTTP response(JSON) to XML output

I am building an application, where I have to hit a restful interface, and pass a specific section of the response to the UI.
The response model is quite huge with a lot of fields(String, array of objects, object,number datatypes), so using manual transformation is a big pain.
Is there a way to map the section of the response to a variable and directly send it to the UI.
I tried,
%dw 2.0
%output application/xml
%var UserAcct= payload.UserResponse.UserDetailsResp.UserAccounts
---
{
User: {
"UserAccount": {
Account: UserAcct
}
}
}
This doesn't work because, the payload has List, Array of Objects etc in the response and mapping to a variable throws an error. Is it possible to send the section payload.UserResponse.UserDetailsResp.UserAccounts directly in dataweave?? Please help.
It will be more helpful if you add Input payload, error and XML output.
Following is the code just by assuming your scenario. You can give this a try:
%dw 2.0
output application/xml
---
{
User: {
"UserAccount": {
(payload.UserResponse.UserDetailsResp.UserAccounts map {
Address:{
<XMLFieldName>: $.<respectiveJSONFieldToMap>
....
}
})
}
}
}

Mulesoft : Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap

I am trying to get the data from Netsuite and save it in the salesforce object using Mulesoft Dataweave element alongwith When-Otherwise as per the snippet below, but gives me error:
Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='/', encoding='null'}" to "CollectionDataType{type=java.util.List, itemType=java.lang.Object, mimeType='/'}".
Not sure how to convert Map to List as I am new to Mulesoft.
If I dont use When-Otherwise, it gives:
"Cannot coerce a :null to a :string error" if the value coming from Netsuite is null.
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
Some_Id__c: payload.customFieldList.customField[0].StringCustomFieldRef__custbody_reference_id as :string when payload.customFieldList.customField[0].StringCustomFieldRef__custbody_reference_id != null otherwise ""
}
]]></dw:set-payload>
</dw:transform-message>
If you need a list, wrap it in square brackets. Also, try using default instead:
[
{
Some_Id__c: payload.customFieldList.customField[0].StringCustomFieldRef__custbody_reference_id as :string default ""
}
]

How to do mapping as arraylist of maps for below using dataweave mule

How to do mapping for below data.
ParameterMap{[card=[15242424211], phone=[54545454545]]}
This data is dynamic which is coming from http request as part queryparameters. I want to form query params in the form #[{'p1':'v1', 'p2':'v2'}] dynamically
for example into [{'card': '15242424211','phone':'54545454545'}]
i.e Array of maps(application/java) Using Dataweave in mule
can you please help on this
use following code
%dw 1.0
%output application/json
---
inboundProperties."http.query.params" mapObject {
($$) : $[0]
}
With this output will be {"card": "15242424211","phone":"54545454545"} you can wrap it under array if required by using
%dw 1.0
%output application/json
---
[inboundProperties."http.query.params" mapObject {
($$) : $[0]
}]
This will produce output as [{"card": "15242424211","phone":"54545454545"}]
Please refer org.mule.module.http.internal.ParameterMap for details of HTTP params.
Hope this help.
Update:-
Please use following for setting query parameters for HTTP outbound request.
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
inboundProperties."http.query.params" mapObject {
($$) : $[0]
}
]]></dw:set-payload>
</dw:transform-message>

DataWeave - Transformer Mule error "There is no variable named 'message'"

How to display Outbound properties in mule via the DataWeave transformer?
I tried this:
%dw 1.0
%output application/json skipNullOn="everywhere"
---
{
test_property: message.outboundProperties.testProperty
}
but I get this error: There is no variable named 'message'.
Thanks.
invoke directly without using 'message' as shown below
test_property: outboundProperties.testProperty
or else define a flow variable and use it as below
flowvar1: flowVars.flowvar1