In operator within an if statement not functioning as expected
I am having trouble understanding why my "in" statement is not producing the expected results. I am attempting to obtain a list of orders, both successes and failures, and also if they failed due to an item being out of stock. After parsing out a list of available quantities (ie [5, 0, 44, 17] ) it still returns "In Stock" for all quantity lists including those with zeros. I want the query to return the string "Out of Stock" if a zero is present in the list. As is everything is working as expected except for this last piece. Any help/suggestions to improve this query and obtain the desired results will be much appreciated. Thanks!
_sourcecategory=*/api/mcs/out AND isOrderable*
| json field=_raw "isOrderable" as success_or_fail
| json field=_raw "distributionCenterInventoryData.*[0].quantityAvailable" as quantityAvailable
| json field=_raw "distributionCenterInventoryData.*[0].vendorDistributionCenterId" as vendorDistributionCenterId
| parse field = vendorDistributionCenterId "[*," as vendorDistributionCenterId
| if("true" matches success_or_fail, "Success", "Fail") as success_or_fail
| if(quantityAvailable in ("[0]" , "[]" , "[0," , ",0]"), "Out of Stock", "In Stock") as stock
-
You can use parse regex field and multi to break up the array of numbers in the field called "quantityAvailable". Then run the if statement to match on ("0" , " " , "[0," , ",0]")
_sourcecategory=*/api/mcs/out AND isOrderable*
| json field=_raw "isOrderable" as success_or_fail
| json field=_raw "distributionCenterInventoryData.*[0].quantityAvailable" as quantityAvailable
| json field=_raw "distributionCenterInventoryData.*[0].vendorDistributionCenterId" as vendorDistributionCenterId
| parse field = vendorDistributionCenterId "[*," as vendorDistributionCenterId
| if("true" matches success_or_fail, "Success", "Fail") as success_or_fail
| parse regex field=quantityavailable "(?:\[|\,|)(?<field1>.*?)(?:\]|\,)" multi
| if(field1 in ("0" , " " , "[0," , ",0]"), "Out of Stock", "In Stock") as stock
Please sign in to leave a comment.
Comments
1 comment