This method creates a new pricing option for an item.
Parameter |
Type |
Description |
---|---|---|
pricing |
The pricing 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 pricing option for the item with the key “TESTINVENTORYITEM0005”. The item was created by the CreateSalesItem example. The pricing and pricing detail object specify the item and the required pricing information. 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; ItemKey itemKey; PriceLevelKey priceLevelKey; CurrencyKey currencyKey; PricingKey pricingKey; Pricing pricing; PricingDetail pricingDetail; PricingDetailKey pricingDetailKey; Quantity toQuantity; PricingDetailPrice detailPrice; MoneyAmount priceAmount; Policy pricingCreatePolicy; // 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 identify the item itemKey = new ItemKey(); itemKey.Id = "TESTINVENTORYITEM0005"; // Create a price level key priceLevelKey = new PriceLevelKey(); priceLevelKey.Id = "RETAIL"; // Create a currency key currencyKey = new CurrencyKey(); currencyKey.ISOCode = "USD"; // Create a pricing key object and populate its key properties pricingKey = new PricingKey(); pricingKey.ItemKey = itemKey; pricingKey.PriceLevelKey = priceLevelKey; pricingKey.CurrencyKey = currencyKey; pricingKey.UofM = "EACH"; // Create a price level object pricing = new Pricing(); // Populate the pricing object key pricing.Key = pricingKey; // Create a pricing detail object pricingDetail = new PricingDetail(); // Create a pricing detail key pricingDetailKey = new PricingDetailKey(); // Populate the pricing detail key with the pricing key pricingDetailKey.PricingKey = pricingKey; // Create a quantity object toQuantity = new Quantity(); // Populate the quantity objects value property with the maximum value toQuantity.Value = 999999999999M; // Populate the pricing detail key ToQuantity property pricingDetailKey.ToQuantity = toQuantity; // Populate the pricing detail key pricingDetail.Key = pricingDetailKey; // Create a pricing detail price object detailPrice = new PricingDetailPrice(); // Create a money amount object to specify the price and currency priceAmount = new MoneyAmount(); priceAmount.Value = 5m; priceAmount.Currency = "USD"; // Populate the pricing detail price item with the amount object detailPrice.Item = priceAmount; // Populate the pricing detail object's UofMPrice with the pricing detail price object pricingDetail.UofMPrice = detailPrice; // Create an array for the pricing detail objects PricingDetail[] pricingDetails = { pricingDetail }; // Add the array of pricing details to the pricing object pricing.Details = pricingDetails; // Get the create policy for price level pricingCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePricing", context); // Create the pricing object wsDynamicsGP.CreatePricing(pricing, context, pricingCreatePolicy); } } }
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; ItemKey itemKey; PriceLevelKey priceLevelKey; CurrencyKey currencyKey; PricingKey pricingKey; Pricing pricing; PricingDetail pricingDetail; PricingDetailKey pricingDetailKey; Quantity toQuantity; PricingDetailPrice detailPrice; MoneyAmount priceAmount; Policy pricingCreatePolicy; // 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 identify the item itemKey = new ItemKey(); itemKey.Id = "TESTINVENTORYITEM0005"; // Create a price level key priceLevelKey = new PriceLevelKey(); priceLevelKey.Id = "RETAIL"; // Create a currency key currencyKey = new CurrencyKey(); currencyKey.ISOCode = "USD"; // Create a pricing key object and populate its key properties pricingKey = new PricingKey(); pricingKey.ItemKey = itemKey; pricingKey.PriceLevelKey = priceLevelKey; pricingKey.CurrencyKey = currencyKey; pricingKey.UofM = "EACH"; // Create a price level object pricing = new Pricing(); // Populate the pricing object key pricing.Key = pricingKey; // Create a pricing detail object pricingDetail = new PricingDetail(); // Create a pricing detail key pricingDetailKey = new PricingDetailKey(); // Populate the pricing detail key with the pricing key pricingDetailKey.PricingKey = pricingKey; // Create a quantity object toQuantity = new Quantity(); // Populate the quantity objects value property with the maximum value toQuantity.Value = 999999999999M; // Populate the pricing detail key ToQuantity property pricingDetailKey.ToQuantity = toQuantity; // Populate the pricing detail key pricingDetail.Key = pricingDetailKey; // Create a pricing detail price object detailPrice = new PricingDetailPrice(); // Create a money amount object to specify the price and currency priceAmount = new MoneyAmount(); priceAmount.Value = 5m; priceAmount.Currency = "USD"; // Populate the pricing detail price item with the amount object detailPrice.Item = priceAmount; // Populate the pricing detail object's UofMPrice with the pricing detail price object pricingDetail.UofMPrice = detailPrice; // Create an array for the pricing detail objects PricingDetail[] pricingDetails = { pricingDetail }; // Add the array of pricing details to the pricing object pricing.Details = pricingDetails; // Get the create policy for price level pricingCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreatePricing", context); // Create the pricing object wsDynamicsGP.CreatePricing(pricing, context, pricingCreatePolicy); // Close the service if(wsDynamicsGP.State != CommunicationState.Faulted) { wsDynamicsGP.Close(); } } } }