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?
%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.