I have a input payload to a MuleSoft application like so …
{
"P_CUST_ACCOUNTS": [
{
"ACCOUNT_NUMBER": 62972,
"ADDR_CHG_FLAG": "N"
},
{
"ACCOUNT_NUMBER": 94561,
"ADDR_CHG_FLAG": null
}
]
}
I need to …
check that each object in the array contains ACCOUNT_NUMBER and ADDR_CHG_FLAG
check that each array object’s ACCOUNT_NUMBER value is not null and is not an empty string
check that each array object’s ADDR_CHG_FLAG value is not null and is not an empty string
… and would like to simply return a true or false based on if all the above conditions are met.
So in the above case, I would get a boolean value of true.
So far, I have been able to get the first condition working with …
%dw 2.0
output application/json
import * from dw::core::Arrays
---
{`your text`
acctnbr: payload.P_CUST_ACCOUNTS every ($.ACCOUNT_NUMBER?),
addrchgflag: payload.P_CUST_ACCOUNTS every ($.ADDR_CHG_FLAG?)else true
}
… but needed to separate each field (like above), as putting them together (like below) to get a single boolean value returned doesn’t return the correct value …
if ((payload.P_CUST_ACCOUNTS every ($.ACCOUNT_NUMBER?) == false)
or (payload.P_CUST_ACCOUNTS every ($.ADDR_CHG_FLAG?) == false)
) false
else true
Wondering if there is a way using dataweave to correctly get a single boolean value based on if all of the conditions above are met.
Thanks in advance.
Tried – mentioned in details above
airmail is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.