CreateInventoryVariance

Description

This method creates a new inventory variance document.

Parameters

Parameter

Type

Description

inventoryVariance

InventoryVariance

The inventory variance object being created.

context

Context

Specifies information about how the method will be called.

policy

Policy

Specifies the set of behaviors and behavior options to be applied during the operation.

Interfaces

  • Dynamics GP
  • Inventory

Examples

The following C# example creates a new inventory variance document with the key "WSINVVAR000000016". The example demonstrates setting the inventory variance document's key, batch key, and date properties. The example uses a single inventory variance line to specify the details of the variance. All other properties use default values.

Cc508613.LegacyEndpoint(en-us,MSDN.10).gif** 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;
            InventoryLineKey inventoryLineKey;
            InventoryVariance inventoryVariance;
            InventoryVarianceLine inventoryVarianceLine;
            Policy inventoryVarianceCreatePolicy;

            // 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 variance object
            inventoryKey = new InventoryKey();
            inventoryKey.Id = "WSINVVAR000000016";

            // Create a batch key object to specify a batch for the inventory variance
            batchKey = new BatchKey();
            batchKey.Id = "INVENTORY BATCH";

            // Create an inventory variance object
            inventoryVariance = new InventoryVariance();

            // Populate the inventory variance object's required properties
            inventoryVariance.Key = inventoryKey;
            inventoryVariance.BatchKey = batchKey;
            inventoryVariance.Date = DateTime.Today;

            // Create an inventory variance line object to detail the inventory variance
            inventoryVarianceLine = new InventoryVarianceLine();

            // Create an inventory line key to identify the inventory variance line object
            inventoryLineKey = new InventoryLineKey();
            inventoryLineKey.InventoryKey = inventoryKey;

            // Create an item key object to specify the item
            itemKey = new ItemKey();
            itemKey.Id = "128 SDRAM";

            // Create a quantity object to specify the amount of the variance
            itemQuantity = new Quantity();
            itemQuantity.Value = 2m;

            // Create a warehouse key to specify the location of the variance
            warehouseKey = new WarehouseKey();
            warehouseKey.Id = "NORTH";

            // Populate the required properties of the inventory variance line object
            inventoryVarianceLine.Key = inventoryLineKey;
            inventoryVarianceLine.ItemKey = itemKey;
            inventoryVarianceLine.Quantity = itemQuantity;
            inventoryVarianceLine.WarehouseKey = warehouseKey;

            // Create an array to hold the inventory variance line object
            InventoryVarianceLine[] lines = { inventoryVarianceLine };

            // Add the array of inventory variance lines to the inventory variance object
            inventoryVariance.Lines = lines;

            // Get the create policy for an inventory variance
            inventoryVarianceCreatePolicy = wsDynamicsGP.GetPolicyByOperation(
            "CreateInventoryVariance", context);

            // Create the inventory variance
            wsDynamicsGP.CreateInventoryVariance(inventoryVariance,
            context, inventoryVarianceCreatePolicy);
        }
    }
}

Cc508613.NativeEndpoint(en-us,MSDN.10).gif** Native endpoint **

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
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;
            InventoryLineKey inventoryLineKey;
            InventoryVariance inventoryVariance;
            InventoryVarianceLine inventoryVarianceLine;
            Policy inventoryVarianceCreatePolicy;

            // 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 variance object
            inventoryKey = new InventoryKey();
            inventoryKey.Id = "WSINVVAR000000016";

            // Create a batch key object to specify a batch for the inventory variance
            batchKey = new BatchKey();
            batchKey.Id = "INVENTORY BATCH";

            // Create an inventory variance object
            inventoryVariance = new InventoryVariance();

            // Populate the inventory variance object's required properties
            inventoryVariance.Key = inventoryKey;
            inventoryVariance.BatchKey = batchKey;
            inventoryVariance.Date = DateTime.Today;

            // Create an inventory variance line object to detail the inventory variance
            inventoryVarianceLine = new InventoryVarianceLine();

            // Create an inventory line key to identify the inventory variance line object
            inventoryLineKey = new InventoryLineKey();
            inventoryLineKey.InventoryKey = inventoryKey;

            // Create an item key object to specify the item
            itemKey = new ItemKey();
            itemKey.Id = "128 SDRAM";

            // Create a quantity object to specify the amount of the variance
            itemQuantity = new Quantity();
            itemQuantity.Value = 2m;

            // Create a warehouse key to specify the location of the variance
            warehouseKey = new WarehouseKey();
            warehouseKey.Id = "NORTH";

            // Populate the required properties of the inventory variance line object
            inventoryVarianceLine.Key = inventoryLineKey;
            inventoryVarianceLine.ItemKey = itemKey;
            inventoryVarianceLine.Quantity = itemQuantity;
            inventoryVarianceLine.WarehouseKey = warehouseKey;

            // Create an array to hold the inventory variance line object
            InventoryVarianceLine[] lines = { inventoryVarianceLine };

            // Add the array of inventory variance lines to the inventory variance object
            inventoryVariance.Lines = lines;

            // Get the create policy for an inventory variance
            inventoryVarianceCreatePolicy = wsDynamicsGP.GetPolicyByOperation(
            "CreateInventoryVariance", context);

            // Create the inventory variance
            wsDynamicsGP.CreateInventoryVariance(inventoryVariance,
            context, inventoryVarianceCreatePolicy);

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