Filtering Properties

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”,
“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
}
],
“collection”: [
{
“href”: “https://shiffonz.sculpt.digital/wp-json/wc/v3/products/1721/variations
}
],
“up”: [
{
“href”: “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/”,
“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/”,
“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

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. 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 and 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.
  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 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.