I have data in cache i.e objectstore. I need to get the data from cache and apply the filter condition on it.
Here requirement is, I have to expose api to get the data based on filedName and filedValue which will come dynamically in the request.
sample request :
https://localhost:8082/api/customer/filter?fieldName=customerId&fieldValue=101810
I have return code to filter the data in dataweave but it is not working. can you please help on this
%dw 1.0
%output application/json
---
payload.rows filter (("$.content." ++ flowVars.fieldName ++ ".content") as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> {
customerId: row.content.customerId.content as :string when row.content.customerId.content != null otherwise null,
customerName: row.content.customerName.content as :string when row.content.customerName.content != null otherwise null,
customerAddress:row.content.customerAddress.content as :string when row.content.customerAddress.content != null otherwise null
})
and I am getting below error
Exception while executing:
payload.rows filter (("$.content." ++ flowVars.fieldName ++ ".content") as :string == flowVars.fieldValue as :string) map ((row , indexOfRow) -> {
^
Type mismatch for '++' operator
found :object, :string
required :string, :string.
can you please help on this
The issue is with the code used for selector it should be like
$.content[flowVars.fieldName].content
. Complete code will beThis worked fine with the input provided by you.
Hope this help.