This method creates a new inventory adjustment document.
Parameter |
Type |
Description |
---|---|---|
inventoryAdjustment |
The inventory adjustment object being created. |
|
context |
Specifies information about how the method will be called. |
|
policy |
Specifies the set of behaviors and behavior options to be applied during the operation. |
The following C# example creates a new inventory adjustment document with the key “WSINVADJ000000015”. The example demonstrates setting the inventory adjustment document’s key, batch key, and date properties. The example also uses a single inventory adjustment line to specify the details of the adjustment. All other properties use default values.
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; BatchKey batchKey; ItemKey itemKey; Quantity itemQuantity; WarehouseKey warehouseKey; InventoryKey inventoryKey; InventoryAdjustment inventoryAdjustment; InventoryLineKey inventoryLineKey; InventoryAdjustmentLine inventoryAdjustmentLine; Policy inventoryAdjustmentCreatePolicy; // 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 inventory key to identify the inventory adjustment object inventoryKey = new InventoryKey(); inventoryKey.Id = "WSINVADJ000000015"; // Create a batch key object to specify a batch for the inventory adjustment batchKey = new BatchKey(); batchKey.Id = "INVENTORY BATCH"; // Create the inventory adjustment object inventoryAdjustment = new InventoryAdjustment(); // Populate the inventory adjustment object's required properties inventoryAdjustment.Key = inventoryKey; inventoryAdjustment.BatchKey = batchKey; inventoryAdjustment.Date = DateTime.Today; // Create an inventory adjustment line object to detail the inventory adjustment inventoryAdjustmentLine = new InventoryAdjustmentLine(); // Create an inventory line key to identify the inventory line adjustment object inventoryLineKey = new InventoryLineKey(); inventoryLineKey.InventoryKey = inventoryKey; // Create an item key object to specify the item itemKey = new ItemKey(); itemKey.Id = "PEN"; // Create a quantity object to specify the amount of the adjustment itemQuantity = new Quantity(); itemQuantity.Value = 1m; // Create a warehouse key to specify the location of the adjustment warehouseKey = new WarehouseKey(); warehouseKey.Id = "WAREHOUSE"; // Populate the required properties of the inventory line adjustment object inventoryAdjustmentLine.Key = inventoryLineKey; inventoryAdjustmentLine.ItemKey = itemKey; inventoryAdjustmentLine.Quantity = itemQuantity; inventoryAdjustmentLine.WarehouseKey = warehouseKey; // Create an array to hold the inventory line adjustment object InventoryAdjustmentLine[] lines = { inventoryAdjustmentLine }; // Add the array of inventory adjustment lines to the inventory adjustment object inventoryAdjustment.Lines = lines; // Get the create policy for an inventory adjustment inventoryAdjustmentCreatePolicy = wsDynamicsGP.GetPolicyByOperation( "CreateInventoryAdjustment", context); // Create the inventory adjustment wsDynamicsGP.CreateInventoryAdjustment(inventoryAdjustment, context, inventoryAdjustmentCreatePolicy); } } }
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; BatchKey batchKey; ItemKey itemKey; Quantity itemQuantity; WarehouseKey warehouseKey; InventoryKey inventoryKey; InventoryAdjustment inventoryAdjustment; InventoryLineKey inventoryLineKey; InventoryAdjustmentLine inventoryAdjustmentLine; Policy inventoryAdjustmentCreatePolicy; // 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 inventory key to identify the inventory adjustment object inventoryKey = new InventoryKey(); inventoryKey.Id = "WSINVADJ000000015"; // Create a batch key object to specify a batch for the inventory adjustment batchKey = new BatchKey(); batchKey.Id = "INVENTORY BATCH"; // Create the inventory adjustment object inventoryAdjustment = new InventoryAdjustment(); // Populate the inventory adjustment object's required properties inventoryAdjustment.Key = inventoryKey; inventoryAdjustment.BatchKey = batchKey; inventoryAdjustment.Date = DateTime.Today; // Create an inventory adjustment line object to detail the inventory adjustment inventoryAdjustmentLine = new InventoryAdjustmentLine(); // Create an inventory line key to identify the inventory line adjustment object inventoryLineKey = new InventoryLineKey(); inventoryLineKey.InventoryKey = inventoryKey; // Create an item key object to specify the item itemKey = new ItemKey(); itemKey.Id = "PEN"; // Create a quantity object to specify the amount of the adjustment itemQuantity = new Quantity(); itemQuantity.Value = 1m; // Create a warehouse key to specify the location of the adjustment warehouseKey = new WarehouseKey(); warehouseKey.Id = "WAREHOUSE"; // Populate the required properties of the inventory line adjustment object inventoryAdjustmentLine.Key = inventoryLineKey; inventoryAdjustmentLine.ItemKey = itemKey; inventoryAdjustmentLine.Quantity = itemQuantity; inventoryAdjustmentLine.WarehouseKey = warehouseKey; // Create an array to hold the inventory line adjustment object InventoryAdjustmentLine[] lines = { inventoryAdjustmentLine }; // Add the array of inventory adjustment lines to the inventory adjustment object inventoryAdjustment.Lines = lines; // Get the create policy for an inventory adjustment inventoryAdjustmentCreatePolicy = wsDynamicsGP.GetPolicyByOperation( "CreateInventoryAdjustment", context); // Create the inventory adjustment wsDynamicsGP.CreateInventoryAdjustment(inventoryAdjustment, context, inventoryAdjustmentCreatePolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }