How to retrieve Quantity On Hand amount using Web Services for Dynamics GP 10.0

Chris RoehrichThis post is due to requests I have come across in the past and very recently in a support incident.  The question raised was how to retrieve quantity amounts like Quantity On Hand for inventory items?  This Visual Studio 2005 (C#) sample shows how to retrieve the Quantity On Hand value for an Inventory Item.  The SalesItem class provides a Quantities property which is a collection of SalesItemWarehouse objects.  The SalesItemWarehouse object contains the different quantity amounts for each Item and Site combination.  These values are stored in the IV00102 table.  

Since we need to retrieve a SalesItem and there is no GetSalesItemByKey method, I used a explicit conversion by casting a SalesItem object to the GetInventoriedItemByKey method:

Code Example

// Cast a SalesItem object to retrieve the SalesItem.Quantities
salesItem = (SalesItem)wsDynamicsGP.GetInventoriedItemByKey(itemKey, context);

The SalesItem class inherits from InventoriedItem and InventoriedItem inherits from the Item class.   This sample shows how to return these OnHandQuantity amounts for each Item and Site combination and also sums the OnHandQuantity amounts to provide a total amount.  To provide the total amount I used an ArrayList (System.Collections namespace) to hold these values and sum them up:

Code Example

// Create an ArrayList of OnHandQuantity values (cast as int)
ArrayList quantities = new ArrayList();

foreach (SalesItemWarehouse salesItemWarehouse in salesItem.Quantities)
{
quantities.Add((int)salesItemWarehouse.OnHandQuantity.Value);
}

// value to hold the sum of the values
int sum = 0;

//sum the values in the arraylist
foreach (int onHandQuantities in quantities)
{
sum += onHandQuantities;
}

// display the sum of the On Hand Quantities
Console.WriteLine("Total On Hand Quantity for " + salesItem.Key.Id +": " + sum.ToString());

If you are interested in returning the Quantity Available, then you would need to subtract the Quantity Allocated amount (AllocatedQuantity) from the Quantity On Hand amount (OnHandQuantity).  This is a calculated field and not exposed as a property of the SalesItemWarehouse object.

The sample is located on the Developer Toolkit Sample Applications for Microsoft Dynamics GP 10.0 Secure Link page in CustomerSource.

I hope you find this post helpful if you encounter this scenario.

Chris

// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, https://opensource.org/licenses/ms-pl.html.)