# Filtering Properties

**URL:** <https://forum.alumio.com/t/filtering-properties/619>\
**Category:** Data Transformers\
**Created:** [May 31, 2023, 1:41pm UTC](https://forum.alumio.com/t/filtering-properties/619 "2023-05-31T13:41:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![abubakar](https://forum.alumio.com/letter_avatar_proxy/v4/letter/a/8491ac/32.png) [@abubakar](https://forum.alumio.com/u/abubakar)\
**Post date:** [May 31, 2023, 1:41pm UTC](https://forum.alumio.com/t/filtering-properties/619/1 "2023-05-31T13:41:33Z")

</div>

In the json data below, i will like to check the “stockAvailability[0].diffgr:diffgram.DocumentElement.StockAvailability” that have an item stock level in branches, now there is quantity object in the root level, i want to generate new object in the “stockAvailability[0].diffgr:diffgram.DocumentElement.StockAvailability.\*” having the number of quantity i can get out of each branch to complete the total quantity required

{  
“id”: 67,  
“name”: “4127 - 16, Red”,  
“product\_id”: 1721,  
“variation\_id”: 1757,  
“quantity”: 4,  
“tax\_class”: “”,  
“subtotal”: “303.80”,  
“subtotal\_tax”: “0.00”,  
“total”: “303.80”,  
“total\_tax”: “0.00”,  
“taxes”: ,  
“meta\_data”: [  
{  
“id”: 707,  
“key”: “pa\_size”,  
“value”: “16”,  
“display\_key”: “Size”,  
“display\_value”: “16”  
},  
{  
“id”: 708,  
“key”: “pa\_colour”,  
“value”: “red”,  
“display\_key”: “Colour”,  
“display\_value”: “Red”  
},  
{  
“id”: 709,  
“key”: “\_reduced\_stock”,  
“value”: “4”,  
“display\_key”: “\_reduced\_stock”,  
“display\_value”: “4”  
}  
],  
“sku”: “4127”,  
“price”: 75.95,  
“image”: {  
“id”: 0,  
“src”: “”  
},  
“parent\_name”: “4127”,  
“barCode\_retrival”: {  
“id”: 1757,  
“date\_created”: “2023-05-30T15:46:01”,  
“date\_created\_gmt”: “2023-05-30T14:46:01”,  
“date\_modified”: “2023-05-30T18:07:18”,  
“date\_modified\_gmt”: “2023-05-30T17:07:18”,  
“description”: “”,  
“permalink”: “[https://shiffonz.sculpt.digital/p/4127/?attribute\_pa\_size=16&attribute\_pa\_colour=red](https://shiffonz.sculpt.digital/p/4127/?attribute_pa_size=16&attribute_pa_colour=red)”,  
“sku”: “4127”,  
“price”: “75.95”,  
“regular\_price”: “139.9”,  
“sale\_price”: “75.95”,  
“date\_on\_sale\_from”: null,  
“date\_on\_sale\_from\_gmt”: null,  
“date\_on\_sale\_to”: null,  
“date\_on\_sale\_to\_gmt”: null,  
“on\_sale”: true,  
“status”: “publish”,  
“purchasable”: true,  
“virtual”: false,  
“downloadable”: false,  
“downloads”: ,  
“download\_limit”: -1,  
“download\_expiry”: -1,  
“tax\_status”: “taxable”,  
“tax\_class”: “”,  
“manage\_stock”: true,  
“stock\_quantity”: 10,  
“stock\_status”: “instock”,  
“backorders”: “no”,  
“backorders\_allowed”: false,  
“backordered”: false,  
“low\_stock\_amount”: null,  
“weight”: “”,  
“dimensions”: {  
“length”: “”,  
“width”: “”,  
“height”: “”  
},  
“shipping\_class”: “”,  
“shipping\_class\_id”: 0,  
“image”: null,  
“attributes”: [  
{  
“id”: 1,  
“name”: “Size”,  
“option”: “16”  
},  
{  
“id”: 2,  
“name”: “Colour”,  
“option”: “Red”  
}  
],  
“menu\_order”: 36,  
“meta\_data”: [  
{  
“id”: 56921,  
“key”: “\_barcode”,  
“value”: “0000000685672”  
},  
{  
“id”: 56995,  
“key”: “wcmlim\_stock\_at\_223”,  
“value”: “1”  
},  
{  
“id”: 56996,  
“key”: “wcmlim\_regular\_price\_at\_223”,  
“value”: “”  
},  
{  
“id”: 56997,  
“key”: “wcmlim\_sale\_price\_at\_223”,  
“value”: “”  
},  
{  
“id”: 56998,  
“key”: “wcmlim\_cogs\_at\_223”,  
“value”: “”  
},  
{  
“id”: 56999,  
“key”: “wcmlim\_regular\_price\_at\_222”,  
“value”: “”  
},  
{  
“id”: 57000,  
“key”: “wcmlim\_sale\_price\_at\_222”,  
“value”: “”  
},  
{  
“id”: 57001,  
“key”: “wcmlim\_cogs\_at\_222”,  
“value”: “”  
},  
{  
“id”: 57002,  
“key”: “wcmlim\_regular\_price\_at\_220”,  
“value”: “”  
},  
{  
“id”: 57003,  
“key”: “wcmlim\_sale\_price\_at\_220”,  
“value”: “”  
},  
{  
“id”: 57004,  
“key”: “wcmlim\_cogs\_at\_220”,  
“value”: “”  
},  
{  
“id”: 57005,  
“key”: “wcmlim\_regular\_price\_at\_219”,  
“value”: “”  
},  
{  
“id”: 57006,  
“key”: “wcmlim\_sale\_price\_at\_219”,  
“value”: “”  
},  
{  
“id”: 57007,  
“key”: “wcmlim\_cogs\_at\_219”,  
“value”: “”  
},  
{  
“id”: 57008,  
“key”: “wcmlim\_regular\_price\_at\_221”,  
“value”: “”  
},  
{  
“id”: 57009,  
“key”: “wcmlim\_sale\_price\_at\_221”,  
“value”: “”  
},  
{  
“id”: 57010,  
“key”: “wcmlim\_cogs\_at\_221”,  
“value”: “”  
},  
{  
“id”: 57011,  
“key”: “purchase\_price”,  
“value”: “”  
},  
{  
“id”: 57012,  
“key”: “\_wc\_additional\_variation\_images”,  
“value”: “”  
},  
{  
“id”: 57015,  
“key”: “wcmlim\_stock\_at\_222”,  
“value”: “13”  
}  
],  
“\_links”: {  
“self”: [  
{  
“href”: “[https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations/1757](https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations/1757)”  
}  
],  
“collection”: [  
{  
“href”: “[https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations](https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations)”  
}  
],  
“up”: [  
{  
“href”: “[https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721](https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721)”  
}  
]  
}  
},  
“\_barCode”: [  
“0000000685672”  
],  
“note”: “”,  
“currency”: “GBP”,  
“order\_id”: 1761,  
“payment\_method”: “”,  
“customer\_id\_inner”: 14,  
“order\_date\_created”: [  
[  
“2023”,  
“05”,  
“30”  
],  
“17:57:56”  
],  
“customer\_info”: “abubakar@micro1.ai”,  
“fm\_retail\_customer\_info”: [  
{  
“@xmlns”: “[https://www.fashionmaster.co.uk/](https://www.fashionmaster.co.uk/)”,  
“xs:schema”: {  
“@id”: “NewDataSet”,  
“xs:element”: {  
“@name”: “NewDataSet”,  
“@msdata:IsDataSet”: “true”,  
“@msdata:MainDataTable”: “CustomerDetails”,  
“@msdata:UseCurrentLocale”: “true”,  
“xs:complexType”: {  
“xs:choice”: {  
“@minOccurs”: 0,  
“@maxOccurs”: “unbounded”,  
“xs:element”: {  
“@name”: “CustomerDetails”,  
“xs:complexType”: {  
“xs:sequence”: {  
“xs:element”: [  
{  
“@name”: “FMCustomerCode”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “FMCustNo”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “WebCustomerCode”,  
“@type”: “xs:long”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “AltCustCode”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Email”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “CompanyName”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Surname”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Forename”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Title”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Address1”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Address2”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Town”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “County”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “PostCode”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Country”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Telephone1”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Telephone2”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “WholesaleCustomer”,  
“@type”: “xs:int”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “LoyaltyCardNumber”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “WhereHeardAboutUs”,  
“@type”: “xs:int”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “WhereHeardAboutUsSpecific”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “PostageCode”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “RecordCreated”,  
“@type”: “xs:dateTime”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “RecordAmended”,  
“@type”: “xs:dateTime”,  
“@minOccurs”: 0,  
“#”: “”  
}  
]  
}  
}  
}  
}  
}  
}  
},  
“diffgr:diffgram”: {  
“DocumentElement”: {  
“CustomerDetails”: {  
“@diffgr:id”: “CustomerDetails1”,  
“@msdata:rowOrder”: 0,  
“FMCustomerCode”: “MIC00001”,  
“FMCustNo”: “MIC00001”,  
“WebCustomerCode”: “0”,  
“AltCustCode”: “123M”,  
“Email”: “abubakar@micro1.ai”,  
“CompanyName”: “Micro1”,  
“Surname”: “Abubakar”,  
“Forename”: “Bello”,  
“Title”: “Mr”,  
“Address1”: “test addres address”,  
“Address2”: “test addres address”,  
“Town”: “chelsea”,  
“County”: “UK”,  
“PostCode”: “1290”,  
“Country”: “UK”,  
“Telephone1”: “123456789”,  
“Telephone2”: “”,  
“WholesaleCustomer”: “0”,  
“LoyaltyCardNumber”: “”,  
“WhereHeardAboutUs”: “0”,  
“WhereHeardAboutUsSpecific”: “”,  
“PostageCode”: {  
“@xml:space”: “preserve”,  
“#”: " "  
},  
“RecordCreated”: “2023-03-02T08:15:40.327+00:00”,  
“RecordAmended”: “2023-05-30T12:06:37.56+01:00”  
}  
}  
}  
}  
],  
“fmCustomerCode”: “MIC00001”,  
“stockAvailability”: [  
{  
“@xmlns”: “[https://www.fashionmaster.co.uk/](https://www.fashionmaster.co.uk/)”,  
“xs:schema”: {  
“@id”: “NewDataSet”,  
“xs:element”: {  
“@name”: “NewDataSet”,  
“@msdata:IsDataSet”: “true”,  
“@msdata:MainDataTable”: “StockAvailability”,  
“@msdata:UseCurrentLocale”: “true”,  
“xs:complexType”: {  
“xs:choice”: {  
“@minOccurs”: 0,  
“@maxOccurs”: “unbounded”,  
“xs:element”: {  
“@name”: “StockAvailability”,  
“xs:complexType”: {  
“xs:sequence”: {  
“xs:element”: [  
{  
“@name”: “BranchNumber”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “BranchName”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Address1”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Address3”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Address4”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Postcode”,  
“@type”: “xs:string”,  
“@minOccurs”: 0,  
“#”: “”  
},  
{  
“@name”: “Stock”,  
“@type”: “xs:int”,  
“@minOccurs”: 0,  
“#”: “”  
}  
]  
}  
}  
}  
}  
}  
}  
},  
“diffgr:diffgram”: {  
“DocumentElement”: {  
“StockAvailability”: [  
{  
“@diffgr:id”: “StockAvailability1”,  
“@msdata:rowOrder”: 0,  
“BranchNumber”: “004”,  
“BranchName”: “BIRMINGHAM SHOP”,  
“Address1”: “369 Stratford Rd,”,  
“Address3”: “”,  
“Address4”: “”,  
“Postcode”: "B11 4JY ",  
“Stock”: “1”  
},  
{  
“@diffgr:id”: “StockAvailability2”,  
“@msdata:rowOrder”: 1,  
“BranchNumber”: “007”,  
“BranchName”: “BRADFORD LEEDS ROAD”,  
“Address1”: “77 LEEDS ROAD”,  
“Address3”: “”,  
“Address4”: “”,  
“Postcode”: “BD3 8BZ”,  
“Stock”: “2”  
}  
]  
}  
}  
}  
]  
}

expected result since the quantity is 4, i should expect the stockAvailability to be

[{  
“@diffgr:id”: “StockAvailability1”,  
“@msdata:rowOrder”: 0,  
“BranchNumber”: “004”,  
“BranchName”: “BIRMINGHAM SHOP”,  
“Address1”: “369 Stratford Rd,”,  
“Address3”: “”,  
“Address4”: “”,  
“Postcode”: "B11 4JY ",  
“Stock”: “1”,  
"quantity: “1”  
},  
{  
“@diffgr:id”: “StockAvailability2”,  
“@msdata:rowOrder”: 1,  
“BranchNumber”: “007”,  
“BranchName”: “BRADFORD LEEDS ROAD”,  
“Address1”: “77 LEEDS ROAD”,  
“Address3”: “”,  
“Address4”: “”,  
“Postcode”: “BD3 8BZ”,  
“Stock”: “2”,  
"quantity: “2”

```
        }

```

]

which means the new quantity object created carries the number of item i can get out of each branches to make up the total

if the quantity is 2 then it means i will get the below result

[{  
“@diffgr:id”: “StockAvailability1”,  
“@msdata:rowOrder”: 0,  
“BranchNumber”: “004”,  
“BranchName”: “BIRMINGHAM SHOP”,  
“Address1”: “369 Stratford Rd,”,  
“Address3”: “”,  
“Address4”: “”,  
“Postcode”: "B11 4JY ",  
“Stock”: “1”,  
"quantity: “0”  
},  
{  
“@diffgr:id”: “StockAvailability2”,  
“@msdata:rowOrder”: 1,  
“BranchNumber”: “007”,  
“BranchName”: “BRADFORD LEEDS ROAD”,  
“Address1”: “77 LEEDS ROAD”,  
“Address3”: “”,  
“Address4”: “”,  
“Postcode”: “BD3 8BZ”,  
“Stock”: “2”,  
"quantity: “2”

```
        }

```

]

because branch two already have the total or they can share and pick 1 from each branches

---

<div class="post-metadata">

**Author:** ![Gugi](https://forum.alumio.com/user_avatar/forum.alumio.com/gugi/32/236_2.png) [@Gugi](https://forum.alumio.com/u/Gugi)\
**Post date:** [June 1, 2023, 5:14pm UTC](https://forum.alumio.com/t/filtering-properties/619/2 "2023-06-01T17:14:26Z")

</div>

Hi @abubakar

In order to achieve the objective, we need to be able to set the remaining quantity variable whenever we have finished setting the quantity needed from each branch in a loop. Unfortunately, Alumio cannot get any properties and their values from outside of each branch object without the “Recursively copy values to children”. Furthermore, we also cannot modify any of them. The only way I can think of is to store the remaining quantity variable inside storage. Something that we can easily read and write, no matter the position in the entity.

Please find the below steps we could do to achieve the objective.

1. Create a unique storage identifier to prevent any collision between calculations. I would recommend using the current timestamp (including microseconds). You can refer to [How to map with Format: Date](https://forum.alumio.com/t/how-to-map-with-format-date/380). You can combine it with any unique value within the entity. We could name the property as `process_id`.
2. Store the remaining quantity to a storage using the value of the `process_id` as the entity identifier.
3. If you prefer to use the stock from the branches that have a higher number of `Stock` first, you can sort the `StockAvailability` array by the value of the `Stock` property. You can use the JMESPath built-in functions [sort\_by](https://jmespath.org/specification.html#sort-by) and [reverse](https://jmespath.org/specification.html#reverse) to sort the array by specific property descendingly. This way, the loop will start from the branch that have the most `stock` to the least one.
4. Since we’re going to get the remaining quantity stored in the storage inside each object of `StockAvailability` array, we need to copy the `process_id` to each object of the array using `Recursively copy values to children`.
5. Loop the `StockAvailability` array using [Node, transform nodes](https://forum.alumio.com/t/node-transformer/348).
6. Within each object, get the remaining quantity using “Get an entity from a storage” with the copied `process_id` and put it as something like `expected`.
7. Subtract it with the `stock` using [Operator Transformer](https://forum.alumio.com/t/operator-transformer/286) and put the result as `remainingQty`.
8. Save the `remainingQty` back to the same storage with the same `process_id`.
9. Put a conditional where if `remainingQty` is greater than `0`, then the used `quantity` should be the same to the `stock` of the branch. Otherwise, set the used `quantity` as same as the `expected`.
10. There must be a condition where the total quantity has been fulfilled, even though we still have branches whose `stock` is not even used. Due to the subtraction and the conditional done previously, the `quantity` will be a negative number. We can put a conditional or Value mapper to change it to `0` if the number is negative.
11. Delete the storage entity used for the calculation using “Delete an entity from a storage” to prevent the increment of the number of storage entities.

The above steps are quite long but can actually be used to spread the stock usage between the branches. I hope the explanation is clear to you.

Please let us know if you have any questions.
