Hi all, I am having trouble with additioning some values from a sub array in Alumio. What would be the way to do this?
For example I got this array:
{
"100001": {
"0": {
"MerchantProductNo": "100001",
"Quantity": -1,
"Code": "CreditOnly"
},
"RejectedQuantity": 0,
"AcceptedQuantity": 0
},
"107058": {
"0": {
"MerchantProductNo": "107058",
"Quantity": -1,
"Code": "GoodsRet"
},
"RejectedQuantity": 0,
"AcceptedQuantity": 0
},
"107183": {
"0": {
"MerchantProductNo": "107183",
"Quantity": -1,
"Code": "Scrap"
},
"RejectedQuantity": 0,
"AcceptedQuantity": 0
},
"107184": {
"0": {
"MerchantProductNo": "107184",
"Quantity": -1,
"Code": "GoodsRet"
},
"1": {
"MerchantProductNo": "107184",
"Quantity": -1,
"Code": "NoReceive"
},
"2": {
"MerchantProductNo": "107184",
"Quantity": 1,
"Code": "NoReceive"
},
"RejectedQuantity": 0,
"AcceptedQuantity": 0
}
}
Each line is grouped based on Item. I have added the RejectedQuantity and AcceptedQuantity as fields that I need to fill based on the quantity values in the array.
Criteria:
- Any minus quantity should be made absolute and additioned as value on AcceptedQuantity
- Any positive quantity should be additioned on RejectedQuantity.
- If the quantity is negative and the code is NoReceive this line should be skipped and not counted as AcceptedQuantity.
The end result in this case should be:
{
"100001": {
"RejectedQuantity": 0,
"AcceptedQuantity": 1
},
"107058": {
"RejectedQuantity": 0,
"AcceptedQuantity": 1
},
"RejectedQuantity": 0,
"AcceptedQuantity": 1
},
"107184": {
"RejectedQuantity": 1,
"AcceptedQuantity": 1
}
}
The problem is that when I use a node transformer I cannot reach outside the node transformer (one node earlier) and when I do not use a node transformer I can not use multiple conditions for the same node.
For example this does not work:
{
"type": "transformer",
"specification": {
"prototype": "conditional",
"parameters": {
"filters": [
{
"prototype": "and-condition",
"parameters": {
"filters": [
{
"prototype": "value-condition-v2",
"parameters": {
"conditions": [
{
"prototype": "number-greater-than",
"parameters": {
"value": 0
}
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"keys": [
"Quantity"
],
"pattern": "*"
}
}
}
},
{
"prototype": "value-condition-v2",
"parameters": {
"conditions": [
{
"prototype": "equals",
"parameters": {
"value": "NoReceive"
}
}
],
"accessor": {
"prototype": "pattern",
"parameters": {
"keys": [
"Code"
],
"pattern": "*"
}
}
}
}
]
}
}
],
"transformers": [
{
"prototype": "operator",
"parameters": {
"operator": "addition",
"left": "RejectedQuantity",
"right": "$1.Quantity"
}
}
],
"elseCases": [],
"elseTransformers": []
}
}
}
Anyone that can help me figure this out in Alumio? My JMESPath knowledge/skill is limited as well, maybe something handy in that area to make this work?
All help is welcome