Hello,
I'm trying to update some purchase order line fields by using this code:
public string UpdatePo(object itemKey, DateTime PromissedShipDate, DateTime PromissedDate, string Quantity, string UnitCost)
{
DynamicsGPClient client = new DynamicsGPClient();
Context context = new Context();
CompanyKey companyKey = new CompanyKey();
companyKey.Id = (Convert.ToInt16(this.companyNo));
context.OrganizationKey = (OrganizationKey)companyKey;
// change
ItemKey key = (ItemKey)itemKey;
PurchaseOrderLine line = PurchaseOrder.Lines.Where(x => x.ItemKey.Id == key.Id).Select(x => x).FirstOrDefault();
line.PromisedShipDate = PromissedShipDate;
line.PromisedDate = PromissedDate;
line.QuantityOrdered.Value = Convert.ToDecimal(Quantity);
line.UnitCost.Value = Convert.ToDecimal(UnitCost);
// save
try
{
Policy purchaseOrderUpdatePolicy = client.GetPolicyByOperation("UpdatePurchaseOrder", context);
client.UpdatePurchaseOrder(this.PurchaseOrder, context, purchaseOrderUpdatePolicy);
return null;
}
catch (Exception ex)
{
return ex.Message;
}
}I am getting this exception:
A validation exception has occurred.
Validation Errors:
- WarehouseKey has not been assigned to ItemKey in Inventory.
- This budget or cost category does not allow an inventoried item
- Document Date is required for PA
- Unable to calculate PABBeginDate info
- A validation error has occurred.
Can somebody help me please? Thanks.
Ubi