Skip to main content

#DataWeave0 personne en discute

 How do I map corresponding elements in dataweave for eg: map CUSTOMER_ID : 790280, CUSTOMER_NAME : JAMES

[

["CUSTOMER_ID", "CUSTOMER_NAME", "AGE", "ADDRESS", "DESCRIPTION"],

["790280", "JAMES", "25", "", ""]

]

#DWL2.0 #DataWeave

11 réponses
  1. 14 avr. 2020, 17:38

    Yup sure @Bharath Kumar N J​ ,

    I have two solutions in this case:

    Solution 1:

    In last script, remove the filter from the end as under:

    %dw 2.0

    output application/json

    ---

    read((write(payload)

    replace '[' with '' replace ']' with '' replace ', \n ' with ','

    replace '\n , \n' with '' replace ' ' with ''), 'application/csv')

    Solution 2: Use another script as under:

    %dw 2.0

    output application/json

    ---

    (payload[1 to -1] map (item, index) -> (item reduce ((item1, acc1={}) -> acc1 ++ ('key') : item1)))map (object) -> (object mapObject ((value, key, index) -> (payload[0][index]): value))

    Both worked fine for me. Already tested.

    Once it will work for you, upvote the answer, so that if someone else have same issue, then they may get the correct solution.

     

    Regards,

     

    Lalit Panwar

0/9000

Loops in Mulesoft

 

Say goodbye to life's predictable loops and embrace a new path for the coming year by tapping into the power of MuleSoft loops.

 

For a comprehensive dive into the world of MuleSoft loops, check out article:  🙌 https://medium.com/another-integration-blog/loops-in-mulesoft-804aa1f4be09

 

#MuleSoft #Integration #Looping Actions #Foreach #Batch Management #Parallel Functionality #DataWeave 

0/9000

Hi All,

Here I need update a value based on filter selector

 

{

  "entries": [

   {

     "FirstName": "Joe",

     "LastName" : "Smith",

     "Company": "Salesforce",

     "Email" : "test@salesforce.com"

    },

    {

     "FirstName": "Max",

     "LastName" : "Minny",

     "Company": "MuleSoft",

     "Email" : "test@mulesoft.com"

    },

    {

     "FirstName": "Tony",

     "LastName" : "Blue",

     "Company": "Salesforce",

     "Email" : "test2@salesforce.com"

    }

  ]

}

 

#DATAWEAVE SCRIPT

 

%dw 2.0

output application/json

---

payload.entries[?($.Company == "Salesforce")]

 

====

 

%dw 2.0

output application/json

---

payload update {

case .entries[0].FirstName -> ""

//.entries[?($.Company == "Salesforce")]

}

 

here based on Company name I should update value

 

Thank you in advance

3 réponses
  1. 4 janv. 2024, 09:46

    Hi @Janardhan Chandaka​ 

     

    Please check the script below.

     

    %dw 2.0

    output application/json

    ---

    "entries": payload.entries map((item,index)->

    if(item.Company=="Salesforce")

    item update {case .FirstName -> "Updated Name"}

    else

    item

    )

    Thanks

    Raghavendra

0/9000

Hi All,

Here I need update a value based on filter selector

 

{

  "entries": [

   {

     "FirstName": "Joe",

     "LastName" : "Smith",

     "Company": "Salesforce",

     "Email" : "test@salesforce.com"

    },

    {

     "FirstName": "Max",

     "LastName" : "Minny",

     "Company": "MuleSoft",

     "Email" : "test@mulesoft.com"

    },

    {

     "FirstName": "Tony",

     "LastName" : "Blue",

     "Company": "Salesforce",

     "Email" : "test2@salesforce.com"

    }

  ]

}

 

#DATAWEAVE SCRIPT

 

%dw 2.0

output application/json

---

payload.entries[?($.Company == "Salesforce")]

 

====

 

%dw 2.0

output application/json

---

payload update {

case .entries[0].FirstName -> ""

//.entries[?($.Company == "Salesforce")]

}

 

here based on Company name I should update value

 

Thank you in advance

0/9000

Watch Dreamforce Developer Innovations on Salesforce +

You can catch up on some of the incredible

#Dreamforce

sessions for developers on demand on our Salesforce + streaming channel.

Check it out!

https://www.salesforce.com/plus/experience/dreamforce_2023/series/developers_at_dreamforce_2023Watch Dreamforce Developer Innovations on Salesforce +You can catch up on some of the incredible sessions for developers on demand on our Salesforce + streaming channel.#DF23 #GraphQL #Developer Tools #Code Builder #Generative AI #Einstein #LWC #DataWeave #Apex
0/9000