Skip to main content

#MuleSoft DataWeave5 人がディスカッション中

Questions and answers about MuleSoft DataWeave, best practices, and use cases.
7 件の回答
  1. 9月12日 5:41

    In Mule 4, you can convert JSON data to PDF by first transforming the JSON into an HTML or other printable format and then generating the PDF using a suitable PDF library or connector. 

     

    For simple datasets, DataWeave can be used to format the JSON values into an HTML document, which can then be converted to PDF. If you have a large JSON file or need a more straightforward approach without developing a custom Mule flow, a dedicated tool can be easier.

    SysTools JSON to PDF Converter can convert JSON files into PDF format while keeping the data readable and organized, making it useful when the goal is simply to obtain a shareable or printable PDF rather than build a complete conversion workflow in Mule 4.

0/9000

*.xxxr.usa-e2.cloudhub.io

The call fails from SAP with the following error:

SOAP:1,023 SRT: Processing error in Internet Communication Framework: ("ICF Error when receiving the response: ICM_HTTP_SSL_ERROR")

We reviewed the certificate chain presented by the CloudHub 2 endpoint and imported the following certificates into SAP STRUST:

The certificate chain validates successfully outside SAP.

However, SAP ECC still reports ICM_HTTP_SSL_ERROR when calling the MuleSoft endpoint.

Has anyone experienced this issue with SAP ECC and the newer Let's Encrypt certificate chain used by CloudHub 2?

Specifically, I would like to confirm:

  1.  Which SAP STRUST PSE should contain the CA certificates for an outbound HTTPS SOAP call: SSL Client Anonymous or SSL Client Standard
  2.  Is the CloudHub leaf/server certificate required in STRUST, or should only the CA/intermediate certificates be trusted? 
  3.  Are there known compatibility issues between older SAPCRYPTOLIB versions and the newer YR1 / ISRG Root YR Let's Encrypt chain? 
  4.  Does SAP ICM need to be restarted/reloaded after updating the certificate list? 
  5.  Is there any special TLS/SNI configuration required when SAP ECC calls a CloudHub 2 endpoint? 

MuleSoft itself is available and the endpoint can be reached successfully from other HTTPS clients.

Any guidance on what to check in SAP SMICM/STRUST or CloudHub 2 would be appreciated.

Thanks!

  

Hi everyone,  We are experiencing an SSL/TLS connectivity issue between SAP ECC and a MuleSoft application deployed on CloudHub 2.0.  SAP ECC is acting as the HTTPS client and is calling a MuleSoft endpoint hosted under:

 

 

 

#MuleSoft DataWeave

0/9000

My Input will get as below String like:

 

[{

"ComplteDate in 180 days"

}] 

 

The scenario like I need to filter the data from source based on field called "ComplteDate" using this date field need to fetch data with WhereClause =[ComplteDate]<= dateadd(dd,180,Cast(getdate() as date) )

Example payload in Data source :[

  {

    "PerformNumber": "C-81022",

    "Status": "In Progress",

    "ComplteDate": "2028-05-01"

  },

  {

    "PerformNumber": "C-81023",

    "Status": "In Progress",

    "ComplteDate": "2029-09-01"

  },

  {

    "PerformNumber": "C-81024",

    "Status": "In Progress",

    "ComplteDate": "2028-05-01"

  },

  {

    "PerformNumber": "C-81024",

    "Status": "In Progress",

    "ComplteDate": "2029-09-01"

  },

  {

    "PerformNumber": "C-81025",

    "Status": "In Progress",

    "ComplteDate": "2028-05-01"

  },

  {

    "PerformNumber": "C-81026",

    "Status": "In Progress",

    "ComplteDate": "2029-09-01"

  },

  {

    "PerformNumber": "C-81026",

    "Status": "In Progress",

    "ComplteDate": "2025-05-01"

  },

  {

    "PerformNumber": "C-81027",

    "Status": "In Progress",

    "ComplteDate": "2025-09-01"

  },

  {

    "PerformNumber": "C-81028",

    "Status": "In Progress",

    "ComplteDate": "2025-05-01"

  },

  {

    "PerformNumber": "C-81029",

    "Status": "In Progress",

    "ComplteDate": "2025-09-01"

  }

]

2 件の回答
  1. 9月10日 15:35

    Hi Vya, 

     

    Here's the DataWeave 2.0 script for this filter (ComplteDate <= today + 180 days): 

     

    %dw 2.0 

    output application/json 

    var cutoffDate = (now() as Date) + |P180D| 

    --- 

    payload filter ( 

        (item.ComplteDate as Date {format: "yyyy-MM-dd"}) <= cutoffDate 

     

    Applied to your sample payload, this returns: 

     

    %dw 2.0 

    output application/json 

    var cutoffDate = (now() as Date) + |P180D| 

    --- 

    payload filter ( 

        (item.ComplteDate as Date {format: "yyyy-MM-dd"}) <= cutoffDate 

     

    Key points on how this works: 

     

    1. now() returns the current DateTime. Casting it to Date strips the time portion, so you're comparing pure dates, not datetime with time-of-day noise. 

    Reference:

    https://docs.mulesoft.com/dataweave/latest/dw-core-functions-now

     

     

    2. |P180D| is a Period literal representing 180 days, this is DataWeave's native way of expressing durations (Period type), introduced in DataWeave 2.4.0. Adding it directly to a Date value shifts the date forward by that period. 

    Reference:

    https://docs.mulesoft.com/dataweave/latest/dw-periods-functions-period

     

     

    3. item.ComplteDate as Date {format: "yyyy-MM-dd"}: your ComplteDate field comes in as a String ("2028-05-01"), so it needs an explicit cast to Date with the matching format before it can be compared against another Date value. Comparing a String directly against a Date will not work correctly. 

     

    4. filter iterates the array and keeps only elements where the condition evaluates true, standard DataWeave array function, no import needed for filter itself (only the Dates/Periods module functions need explicit import if you use more advanced ones like today() or the dw::core::Dates module functions). 

     

    If you'd rather use the more explicit Dates module (cleaner syntax for date-only arithmetic, avoids DateTime timezone quirks entirely): 

     

    %dw 2.0 

    import * from dw::core::Dates 

    output application/json 

    var cutoffDate = today() plusDays 180 

    --- 

    payload filter ((item.ComplteDate as Date {format: "yyyy-MM-dd"}) <= cutoffDate) 

     

    Reference:

    https://docs.mulesoft.com/dataweave/latest/dw-dates

     

     

    Either version works, the second is arguably more readable for pure date math since it avoids mixing DateTime and Date casting.

0/9000

How to Skip attribute or key ( eg SSN, password - sensitive )while transforming the object using mapObject

 

Payload:

[

{

"personal_information": {

"first_name": "Emiliano",

"middle_name": "Romoaldo",

"last_name": "Lesende",

"ssn": "001-08-84382"

},

"login_information": {

"username": "3miliano",

"password": "mypassword1234"

}

},

{

"personal_information": {

"first_name": "Mariano",

"middle_name": "Toribio",

"last_name": "de Achaval",

"ssn": "002-05-34738"

},

"login_information": {

"username": "machaval",

"password": "mypassword4321"

}

}

]

 

Here I have to remove ssn, password key from.

 

write now I have personal_information, login_information but i hv more attribute on same level

 

looking for dynamic way : except personal_information, login_information other attributes doesnt have sensitive information.

 

I have written below dataweave expression but its giving error. Can someone explain what is the error and solution

 MY code:

 

%dw 2.0

output application/json

// I have to remove sesitive fields like ssn, password from payload

 

---

payload map (value, key)->{

(value mapObject(obj, objKey, index)->

objKey match {

 

case str if( objKey as String == "personal_information" ) -> ( obj- "ssn")

case str if( objKey as String == "personal_information" ) -> ( obj- "password")

else -> obj

}

 

}

5 件の回答
  1. 2023年3月13日 21:35

    Hi @Vidyasagar Mundhe​ ,

     

    Check this script:

    Hi @Vidyasagar Mundhe​ , Check this script:%dw 2.

    %dw 2.4

    output application/json skipNullOn="everywhere"

    var payload = [

    {

    "personal_information": {

    "first_name": "Emiliano",

    "middle_name": "Romoaldo",

    "last_name": "Lesende",

    "ssn": "001-08-84382"

    },

    "login_information": {

    "username": "3miliano",

    "password": "mypassword1234"

    }

    },

    {

    "personal_information": {

    "first_name": "Mariano",

    "middle_name": "Toribio",

    "last_name": "de Achaval",

    "ssn": "002-05-34738"

    },

    "login_information": {

    "username": "machaval",

    "password": "mypassword4321"

    }

    }

    ]

     

    var sensitiveFields = ['ssn','password'] map upper($)

     

    fun processValue (value,key) = if(typeOf(value)~=Object) removeSensitiveData(value)

    else

    (if ((sensitiveFields contains upper(key))) null else value)

    fun removeSensitiveData(item) = item mapObject (value,key) -> (key): processValue(value,key)

     

    ---

    payload map removeSensitiveData($)

    Here I'm walking first through the array of elements, and per each element I'm doing the mapObject. Then I'm checking in a recursive way if the value is an object or not. Based on that I'm removing the content of the attribute if the key is in the list sensitiveFields. With the skipNullOn directive I'm removing it from the result.

    Be aware that it won't remove object in this code, only values.

     

    Hope it helps

     

    Good luck!

    Juan Cruz Basso

0/9000

Mule Dataweave - Converting XML to JSON Arrayunble to convert xml to json array in dataweave 2.0

 

output :

"employees":{

"employee":{

"name" : "abc"

},

"employee":{

"name" : "xyz"

}

}

 

expected output :

"employees":{

"employee" : [

{ "name" : "abc" },

{ "name" : "xyz" }

]

 

dataweave script :

 

%dw 2.0

output application/json

---

payload

 

6 件の回答
  1. 2019年1月11日 17:08

    Hi @tejakkk ,

     

    Could you try using next?

     

    %dw 2.0

    output application/java

    ---

    {"employees":{

    "employee":

    (payload.employees.*employee map{

    "name":$.name

    } )

    }

    }

     

    I hope the above helps! If you have any doubt do not hesitate to contact me.

     

    Regards,

     

    Arianna Flores

0/9000

My input is :

[ {

"Booking Loca" : [ "Seedict Sparango","Cando Wall Communities","Maul O'donor","Ahohn kappler" ]

} ]

 

in this input there is a chance to get Name coming like Maul O'donor but I need to replace one single quote to Maul O''donor

 

The final Output Required Like below :

[Booking Loca] in ('Seedict Sparango','Cando Wall Communities','Maul O''donor','Ahohn kappler')

 

for this I am using below Data weave logic but at beginning and ending not getting single quote instead

%dw 2.0

output application/java

import * from dw::core::Strings

---

"[Booking Loca] in ("++((flatten(payload."Booking Loca")) map (wrapWith($,"'")) joinBy ",") replace "'" with '"' replace '","' with "','"++ ")"

 

Here I have a struggle with a small transformation hence please help me

1 件の回答
  1. 7月2日 6:19

    Hello, 

     

    Please try the below dataweave.  

     

    %dw 2.0

    output application/java

    ---

    "[Booking Loca] in (" ++

    ((payload[0]."Booking Loca" map ("'" ++ ($ replace "'" with "''") ++ "'")) joinBy ",")

    ++ ")" 

     

    Thanks!

0/9000

%dw 2.0

 

import * from dw::core::Strings

 

var regExDateTime = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/

var regExDate = /^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/

var regExBoolean = /^(true|false)$/

var id= payload.ChangeEventHeader.recordIds[0]

 

output text/plain

---

id

My DW is somewhat big having some calculation for sake of simplicity I just pasted 4 lines of code only.

In that 4 line itself I am getting below error

Scripting language error on expression '%dw 2.0

 

import * from dw::core::Strings

 

var regExDateTime = /\d{4}-[01]\d-[...'. Reason: Unable to resolve reference of payload..

I even tried by defining meta data for payload as like below

 

var id= payload.ChangeEventHeader.recordIds[0] as String 
var id= payload.ChangeEventHeader.recordIds[0] as String  default 'axd123'

But nothing helps

4 件の回答
  1. 6月14日 4:19

    You can simplify it. In Mule 4 DataWeave, you usually don’t need input payload application/json. Just use:

    %dw 2.0

    output application/json

    ---

    {

    myRootElement: payload

    }

    The payload type comes from the message metadata/header (content-type: application/json).

0/9000

I have requirement to call PATCH method of a resource where user can update of the details mentioned in the request . Account ID which is the key is passed as URI. User can update any or all of these parameters. Since request parameters are not fixed i need to dynamically build UPDATE query.

{

   "name": "Mule",

"phone": "888888888",

"balance": "2000",

"billingCity": "London"

}

Below is the dataweave that is written to build set query. I have tried all combinations to execute update query.

 

%dw 2.0

import * from dw::core::Strings

output application/json 

---

((({

name: payload.name default "",

phone: payload.phone default "",

balance: payload.balance default "",

billingcity: payload.billingCity default ""

}pluck (($$)++'='++"\""++($)++"\"") ) 

reduce(item, acc="")-> acc ++ (if(!isEmpty(substringAfter(item,"="))) item++"," else "")) substringBeforeLast(",")) as String 

 

DB query

 

UPDATE account

SET :query

WHERE idaccount = :accID

 

Input parameters

 

output application/java

---

{

query: vars.query,

accID: attributes.uriParams.accID as String

}

 

vars.query is expected as name="Max",phone="9999999999",balance="20000",billingcity="Bangalore" to work properly. However it is not working . Tried replacing escape character with "" but then it doesnt work.

 

"name=\"Max\",phone=\"9999999999\",balance=\"20000\",billingcity=\"Bangalore\""

 

Kindly let me know if any better ideas to make this work

13 件の回答
  1. Shekh Muenuddeen (NTTData) Forum Ambassador
    2020年11月22日 9:01

    Hey,

     

    Another way to do it first create query variable and store below DataWeave logic

    %dw 2.0

    output application/json

    var data = {

    "name": "Mule",

    "phone": "888888888",

    "balance": "2000",

    "billingCity": "London"

    }

    ---

    "UPDATE account SET " ++

    ((data filterObject ((value, key, index) -> (value != null and value != "")) mapObject ((value, key, index) -> {

    myData : (key as String) ++ " = :" ++ (key as String)

    })).*myData joinBy " AND ") ++ "WHERE idaccount = :accID"

    Its gives you query like below I have stored it query variable

    "UPDATE account SET name = :name AND phone = :phone AND balance = :balance AND billingCity = :billingCityWHERE idaccount = :accID"

    Another DataWeave to stored the input parameters its stored like below DataWeave

    %dw 2.0

    output application/json

    var data = {

    "name": "Mule",

    "phone": "888888888",

    "balance": "2000",

    "billingCity": "London"

    }

    ---

    {

    idaccount : "12345678"

    } ++

    (data filterObject ((value, key, index) -> (value != null and value != ""))) default {}

    Output

    {

    "idaccount": "12345678",

    "name": "Mule",

    "phone": "888888888",

    "balance": "2000",

    "billingCity": "London"

    }

    And Finally in the DataBase Update Operation I have provided the both variable query and inputparametes as below

    Hey, Another way to do it first create query variable and store below DataWeave logic%dw 2. 

    SO its dynamic with Paramterized.

     

    Regards,

    Shekh

0/9000

I am getting below error as I have a HTTP requester node where we have a PUT call so there is no response body.

 

So while creating inbound response we get below error on Transform node.

Unable to parse empty input, while reading `payload` as Json

 

If I do a setPaylod like below with empty body then it works.

<set-payload value="#{}" doc:name="Set Payload" doc:id="4d3edefb-a8c4-43af-bfa4-4625f536509f" />

 

However I am looking for a solution to handle this in the transform node itself.Unable to parse empty input, while reading `payload` as JsonPlease let me know how to handle this in transform node in the best possible way ?

11 件の回答
  1. Shekh Muenuddeen (NTTData) Forum Ambassador
    2021年11月24日 16:01

    Hey,

     

    check once with below code in dataweave 2 mule 4

    %dw 2.0

    output application/java

    ---

    if(!isEmpty(payload))

    payload

    else

    null

    As per article its seem content type issue, means request body without content type

    https://help.mulesoft.com/s/article/Unable-to-parse-empty-input-error-with-Dataweave-Mule-4

0/9000

Hi i want to store and reprocessed the records inside the parallel for each , i am using object store to store the record .

  1. how to call the flow again to process the failed record,after parallel for each stopped
  2. how to pass retretive(objec store) payload to request api
  3. how to stop the flow once all failed records are processed

is store and reterive both should present inside the parallel for each flow?parallel for each , reprocessed error records

10 件の回答
  1. 2023年9月15日 22:41

    In my opinion, adding VM connector on your flow will achieve those requirements.

     

    Below is a sample flow to implement pagination which is roughly the same concept. VM listener will keep on firing while there is data published to it.

    In my opinion, adding VM connector on your flow will achieve those requirements. Below is a sample flow to implement pagination which is roughly the same concept. 

    Hope this helps...

0/9000