GP version 10
System.Web.Services.Protocols.SoapException was unhandled
Message=A validation exception has occurred.
Validation Errors:
- ItemKey does not exist.
- U of M does not exist for UofMScheduleKey.
- ItemKey does not exist.
- Unable to create the new Item Currency Record
Here is the method I am trying to run:
public void updatePricing()
{
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 web service
DynamicsGP wsDynamicsGP = new DynamicsGP();
// Be sure the default credentials are used
wsDynamicsGP.UseDefaultCredentials = true;
// Create a context with which to call the web 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;
context.CultureName = "en-US";
// 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
try
{
wsDynamicsGP.CreatePricing(pricing, context, pricingCreatePolicy);
}
catch (Exception err)
{
throw err;
}
*This post is locked for comments