Reputation: 247
I'm trying to insert data on SalesOrderDetail entity, everything works fine, except for the Amount field which remains null. I don't get any error message. Here is an example of my code :
private void beginCreateSalesOrderDetail()
{
SalesOrderDetail orderDetail = new SalesOrderDetail();
orderDetail.SalesOrderId = new EntityReference()
{
Id = id,
LogicalName = "salesorder"
};
orderDetail.Quantity = element.QuantityOnHand;
orderDetail.ProductId = new EntityReference()
{
Id = element.ProductId,
LogicalName = "product"
};
orderDetail.UoMId = new EntityReference()
{
Id = new Guid("8DDD2AFB-73CF-E111-8140-00155D55B216"),
LogicalName = "uom"
};
orderDetail.TransactionCurrencyId = new EntityReference()
{
Id = new Guid("77D695B5-ACB4-E111-97BC-00155D55B216"),
LogicalName = "transactioncurrency"
};
Money Taxe = new Money();
Money Amount = new Money();
Taxe.Value = Convert.ToDecimal(element.totalCharges);
Amount.Value = Convert.ToDecimal(InvoiceTotal);
orderDetail.Tax = Taxe;
orderDetail.BaseAmount = Amount;
orderDetail.PricePerUnit = element.Price;
orderDetail.Description = element.PDesc;
_context.AddToSalesOrderDetailSet(orderDetail);
_context.BeginSaveChanges(EndCreateSalesOrderDetail, orderDetail);
}
private void EndCreateSalesOrderDetail(IAsyncResult result)
{
try
{
_context.EndSaveChanges(result);
}
catch (Exception ex)
{
}
}
Please note that only the amount which remains null
Upvotes: 0
Views: 618
Reputation: 247
I get the solution. Actually, there is a restrictions in crm 2011 to calcul the amounts of products, We have to create a Price List, and associate each product in the list. Thank you.
Upvotes: 1