Convert Mulsoft dataweave code to SnapLogic
Hello, I have the following MuleSoft code im trying to convert into SnapLogic. I have tried everything i can think of and im not getting anywhere. Also, posted below is a sample output from stored procedure and the expected output i need. Thank you for you time and help!
MuleSoft dataWeave Code:
%dw 2.0
output application/json
var payloadGroupByRiskLevel = ((vars.edpResponse.resultSet1 map ((item, index) -> {
"state": item.SupplierLocationStateCode default "No_State_Code",
"country": item.SupplierLocationCode,
"riskLevel": item.RiskLevel
})) groupBy ((item, index) -> item.riskLevel))
var overallRisk = avg((vars.edpResponse.resultSet1 map ((item, index) -> item.AggregateRisk) default [])) as String {format: "0.00"}
---
{
"riskDetails": {
"riskScore": {
"overAllRisk": overallRisk,
"lowRiskCount": sizeOf(payloadGroupByRiskLevel["Low Risk"] default []),
"mediumRiskCount": sizeOf(payloadGroupByRiskLevel["Medium Risk"] default []),
"highRiskCount": sizeOf(payloadGroupByRiskLevel["High Risk"] default []),
"statesByLowRisk": ((payloadGroupByRiskLevel["Low Risk"].state) distinctBy $) orderBy $,
"statesByMediumRisk": ((payloadGroupByRiskLevel["Medium Risk"].state) distinctBy $) orderBy $,
"statesByHighRisk": ((payloadGroupByRiskLevel["High Risk"].state) distinctBy $) orderBy $,
"countriesByLowRisk": ((payloadGroupByRiskLevel["Low Risk"].country) distinctBy $) orderBy $,
"countriesByMediumRisk": ((payloadGroupByRiskLevel["Medium Risk"].country) distinctBy $) orderBy $,
"countriesByHighRisk": ((payloadGroupByRiskLevel["High Risk"].country) distinctBy $) orderBy $,
}
}
}
Output from stored Prodcedure:
{
"riskDetails": {
"riskScore": {
"overAllRisk": “79.83”
"lowRiskCount": 1,
"mediumRiskCount": 0,
"highRiskCount": 2,
"statesByLowRisk": ["No_State_Code"],
"statesByMediumRisk": [],
"statesByHighRisk": ["Minnesota"],
"countriesByLowRisk": ["SWEDEN"],
"countriesByMediumRisk": [],
"countriesByHighRisk": ["AUSTRALIA","UNITED STATES"]
}
}
}
Hello,
You can achieve this by using a Mapper Snap with the following settings:
Try it, and let me know if this helps.
BR,
Aleksandar.