Skip to main content

Notifications

Microsoft Dynamics GP (Archived)

Insert Sales Order Error

Posted on by 585

Hi,

I am using the API to insert sales orders. I receive these errors:

A validation exception has occurred.

Validation Errors:

- PriceListKey is blank. It must be passed in or a default must exist for the transaction.

- The U of M for the item is not specified in the item price list as the default selling U of M.

- U of M does not exist for the Unit of Measure Schedule being used.

Here is my code:

public void CreateOrder(JMAOrder ord, string batchK, string customerID)
{
SalesOrder salesOrder;
SalesDocumentTypeKey salesOrderType;
CustomerKey customerKey;
BatchKey batchKey;
SalesOrderLine salesOrderLine;
ItemKey orderedItem;
Quantity orderedAmount;

if (String.IsNullOrEmpty(customerID))
{
customerID = GPCustomers.MakeCustomerKey(ord.BillingAddress.FirstName, ord.BillingAddress.LastName).Id;
}

// Create a sales order object
salesOrder = new SalesOrder();

// Create a sales document type key for the sales order
salesOrderType = new SalesDocumentTypeKey();
salesOrderType.Type = SalesDocumentType.Order;

// Populate the document type key of the sales order object
salesOrder.DocumentTypeKey = salesOrderType;

// Create a customer key
//customerKey = new CustomerKey();
//customerKey.Id = "JONESJ008";


GPCustomers gp = new GPCustomers(wsDynamicsGP, context);
customerKey = gp.CreateGPCustomer(ord, customerID);


// Set the customer key property of the sales order object
salesOrder.CustomerKey = customerKey;

// Create a batch key
batchKey = new BatchKey();
//batchKey.Id = "SALES ORDERS";
batchKey.Id = batchK;

// Set the batch key property of the sales order object
salesOrder.BatchKey = batchKey;
salesOrder.PriceLevelKey = wsDynamicsGP.GetPriceLevelList(new PriceLevelCriteria(), context).FirstOrDefault().Key;
List<SalesOrderLine> soLines = new List<SalesOrderLine>();
foreach (JMAOrderDetail jd in ord.OrderDetails)
{
GPItems gpi = new GPItems(wsDynamicsGP, context);
ItemKey ik = gpi.CreateInventoryItem(jd.Product);

// Create a sales order line to specify the ordered item
salesOrderLine = new SalesOrderLine();

// Create an item key
//orderedItem = new ItemKey();
//orderedItem.Id = "32X IDE";
//orderedItem.Id = jd.Sku;

// Set the item key property of the sales order line object
salesOrderLine.ItemKey = ik;

// Create a sales order quantity object
orderedAmount = new Quantity();
orderedAmount.Value = jd.Quantity;

// Set the quantity of the sales order line object
salesOrderLine.Quantity = orderedAmount;
soLines.Add(salesOrderLine);
}

// Create an array of sales order lines
// Initialize the array with sales order line object
//SalesOrderLine[] orders = { salesOrderLine };


// Add the sales order line array to the sales order
salesOrder.Lines = soLines.ToArray();


// Create the sales order
wsDynamicsGP.CreateSalesOrder(salesOrder, context, salesOrderCreatePolicy);


}

I believe the real problem is in my inventory item code:

public ItemKey CreateInventoryItem(JMAProduct jmaProduct)
{
ItemKey itemKey;
UofMScheduleKey unitOfMeasureKey;
SalesItem salesItem;

try
{
//TO DO: investigate key issue. Should return it...
var s = wsDynamicsGP.GetInventoriedItemByKey(new ItemKey { Id = jmaProduct.Sku }, context);
return s.Key;
}
catch (Exception)
{
// Create a sales item object
salesItem = new SalesItem();

// Create a sales item key object to identify the sales item
itemKey = new ItemKey();
itemKey.Id = jmaProduct.Sku;

// Populate the sales item key property
salesItem.Key = itemKey;

// Populate the description property
salesItem.Description = jmaProduct.Description;
salesItem.ShortDescription = jmaProduct.Description;
// Create a unit of measure schedule key
unitOfMeasureKey = new UofMScheduleKey();
unitOfMeasureKey.Id = "EACH";
// Populate the unit of measure property
salesItem.UofMScheduleKey = unitOfMeasureKey;
salesItem.Type = ItemType.SalesItem;
// Get the create policy for sales item

// Create the sales item
wsDynamicsGP.CreateSalesItem(salesItem, context, salesItemCreatePolicy);

return salesItem.Key;
}
}

*This post is locked for comments

  • Verified answer
    sandipdjadhav Profile Picture
    sandipdjadhav 18,265 on at
    RE: Insert Sales Order Error

    Hello,

    1)   it seems to be you have not setup UOM Schedule for item.

    2)   Select Items you want to integrate in your sales order then Goto cards-->Items--> 'Go to' button besides print icon--> Price List. Setup Price List for Item(s).

    It should resolve your problem. Let me know how it goes.

    Thanks

    Sandip

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templatesâš¡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,219 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans