GetInventoriedItemByKey


Description

Retrieves a single inventoried item object based on the item key value supplied. Kit objects and SalesItem objects can also be retrieved using this method. For Kit and SalesItem objects, you must cast the object returned from the method to the appropriate object type.

Parameters

Parameter

Type

Description

key

ItemKey

An item key object that specifies the inventoried item to retrieve.

context

Context

Specifies information about how the method will be called.


Return Value:

Value

Type

Description

GetInventoriedItemByKeyResult

InventoriedItem

An inventoried item object.


Interfaces

 

Examples

The following C# example retrieves the inventoried item with the item key “40X IDE”. A message box displays the inventoried item’s description property.

 Legacy endpoint

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			ItemKey itemKey;
			InventoriedItem inventoriedItem;

			// Create an instance of the service
			DynamicsGP wsDynamicsGP = new DynamicsGP();

			// Be sure the default credentials are used
			wsDynamicsGP.UseDefaultCredentials = true;

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create an item key to specify the inventory item
			itemKey = new ItemKey();
			itemKey.Id = "40X IDE";

			// Retrieve the inventoried item object
			inventoriedItem = wsDynamicsGP.GetInventoriedItemByKey(itemKey, context);

			// Display the description from the inventoried item object
			MessageBox.Show("Inventory item description: " + inventoriedItem.Description);
	}
}
}

 Native endpoint

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			ItemKey itemKey;
			InventoriedItem inventoriedItem;

			// Create an instance of the service
			DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create an item key to specify the inventory item
			itemKey = new ItemKey();
			itemKey.Id = "40X IDE";

			// Retrieve the inventoried item object
			inventoriedItem = wsDynamicsGP.GetInventoriedItemByKey(itemKey, context);

			// Display the description from the inventoried item object
			MessageBox.Show("Inventory item description: " + inventoriedItem.Description);

			// Close the service
			if(wsDynamicsGP.State != CommunicationState.Faulted)
			{
				wsDynamicsGP.Close();
		}
	}
}
}

The following C# example retrieves the inventoried items in the “RETAIL” class. It then examines the type of each inventoried item to find out whether it is a sales item or a kit. The GetInventoriedItemByKey() method is used to retrieve the item. Note how the return value of the method is cast to be either a SalesItem object or a Kit object. For SalesItem objects, the tracking option is displayed. For Kit objects, the number of components in the kit is displayed.

 Legacy endpoint

using System;
using System.Collections.Generic;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			LikeRestrictionOfString classIdRestriction;
			InventoriedItemCriteria inventoryItemCriteria;
			InventoriedItemSummary[] inventoryItemSummaries;
			Kit kit;
			SalesItem salesItem;

			// Create an instance of the service
			DynamicsGP wsDynamicsGP = new DynamicsGP();

			// Be sure the default credentials are used
			wsDynamicsGP.UseDefaultCredentials = true;

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create the restriction object
			// Get items in the RETAIL class
			classIdRestriction = new LikeRestrictionOfString();
			classIdRestriction.EqualValue = "RETAIL";

			// Create the inventoried item criteria object
			inventoryItemCriteria = new InventoriedItemCriteria();
			inventoryItemCriteria.ItemClassId = classIdRestriction;

			// Retrieve the list of inventoried item summary objects
			inventoryItemSummaries = wsDynamicsGP.GetInventoriedItemList(inventoryItemCriteria, context);

			// Display a description of each member of the summary object list
			StringBuilder summaryList = new StringBuilder();
			foreach (InventoriedItemSummary a in inventoryItemSummaries)
			{
				// Include the description of the item
				Console.WriteLine("Inventory item description: " + a.Description);

				// Is the item a sales item?
				if (a.Type == InventoriedItemType.SalesItem)
				{
					// Retrieve the inventoried item and cast it to SalesItem so the sales item
					// properties can be retrieved
					salesItem = (SalesItem)wsDynamicsGP.GetInventoriedItemByKey(a.Key, context);

					// Include the RevalueInventory property, which is a SalesItem property
					Console.WriteLine("   Tracking: " + salesItem.TrackingOption.ToString());
			}

				// Is the item a kit?
				if (a.Type == InventoriedItemType.Kit)
				{
					// Retrieve the inventoried item and cast it to Kit so the kit properties
					// can be retrieved
					kit = (Kit)wsDynamicsGP.GetInventoriedItemByKey(a.Key, context);

					// Include the quantity of kit components
					Console.WriteLine("	Number of components: " + kit.Components.Length.ToString()); 		 
			} 
		}

			Console.ReadLine();
	}
}
}

 Native endpoint

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicsGPWebServiceSample.DynamicsGPService;

namespace DynamicsGPWebServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			CompanyKey companyKey;
			Context context;
			LikeRestrictionOfstring classIdRestriction;
			InventoriedItemCriteria inventoryItemCriteria;
			InventoriedItemSummary[] inventoryItemSummaries;
			Kit kit;
			SalesItem salesItem;

			// Create an instance of the service
			DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

			// Create a context with which to call the service
			context = new Context();

			// Specify which company to use (sample company)
			companyKey = new CompanyKey();
			companyKey.Id = (-1);

			// Set up the context object
			context.OrganizationKey = (OrganizationKey)companyKey;

			// Create the restriction object
			// Get items in the RETAIL class
			classIdRestriction = new LikeRestrictionOfstring();
			classIdRestriction.EqualValue = "RETAIL";

			// Create the inventoried item criteria object
			inventoryItemCriteria = new InventoriedItemCriteria();
			inventoryItemCriteria.ItemClassId = classIdRestriction;

			// Retrieve the list of inventoried item summary objects
			inventoryItemSummaries = wsDynamicsGP.GetInventoriedItemList(inventoryItemCriteria, context);

			// Display a description of each member of the summary object list
			StringBuilder summaryList = new StringBuilder();
			foreach (InventoriedItemSummary a in inventoryItemSummaries)
			{
				// Include the description of the item
				Console.WriteLine("Inventory item description: " + a.Description);

				// Is the item a sales item?
				if (a.Type == InventoriedItemType.SalesItem)
				{
					// Retrieve the inventoried item and cast it to SalesItem so the sales item
					// properties can be retrieved
					salesItem = (SalesItem)wsDynamicsGP.GetInventoriedItemByKey(a.Key, context);

					// Include the RevalueInventory property, which is a SalesItem property
					Console.WriteLine("   Tracking: " + salesItem.TrackingOption.ToString());
			}

				// Is the item a kit?
				if (a.Type == InventoriedItemType.Kit)
				{
					// Retrieve the inventoried item and cast it to Kit so the kit properties
					// can be retrieved
					kit = (Kit)wsDynamicsGP.GetInventoriedItemByKey(a.Key, context);

					// Include the quantity of kit components
					Console.WriteLine("	Number of components: " + kit.Components.Length.ToString()); 		 
			} 
		}

			Console.ReadLine();

			// Close the service
			if(wsDynamicsGP.State != CommunicationState.Faulted)
			{
				wsDynamicsGP.Close();
		}
	}
}
}


Documentation Feedback