Skip to main content
Michael Fesser 님이 #MuleSoft DataWeave에 질문했습니다

Below is the dataweave

 

output application/json

import * from dw::core::Strings

var whereParameters = {

   lastName: 's.something',

   firstName: 'se.soemething_else',

   middleName: 'ms.more_stuff'

}

---

' AND ' ++ (((vars.queryParameters mapObject ((value, key, index) -> {

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

})).*myData joinBy ' AND ') )

 

What I am looking to do is replace the key in vars.queryParameters that matches the key in whereParameters with the value from whereParameters for the WHERE clause of some SQL

 

It would be where the "key as String" is. I am wondering the best way to do this. Tried a few things but nothing worked. Would a function call at that point work? Another mapping? Replace?

답변 4개
  1. 2022년 6월 8일 오전 4:14

    %dw 2.0

    output application/json

    import * from dw::core::Strings

    var whereParameters = {

    lastName: 's.something',

    firstName: 'se.soemething_else',

    middleName: 'ms.more_stuff'

    }

    var QueryParameters = {

    lastName: 'Fesser',

    firstName: 'Michael',

    }

    ---

    QueryParameters mapObject (value,key,index) -> {

    (whereParameters[key] default key) : value

    }

    Hey Michael,

    According to what I understood, you want to replace the key in QueryParameters if its found in whereParameters. Hope this code snippet helps. I have added the default condition, for cases where key is not found.