In salesorder entity, I create a write-in line item if I have freight amount. The Line is created if there is a tax on freight. If the freight amount is completely taken out then I want to delete that item. But I get the following error "salesorderdetail With Id = c471fe88-a3cd-e811-a973-000d3a1a9407 Does Not Exist"
In fact the line Id does exists with same id in the db.
Here is the code to insert the line in the salesorder
Guid freightDetailId = new Guid(); Entity freightLine = new Entity("salesorderdetail", freightDetailId); freightLine["salesorderid"] = new EntityReference("salesorder", gEntityId); freightLine["isproductoverridden"] = true; freightLine["priceperunit"] = new Money(0); freightLine["quantity"] = Convert.ToDecimal(1); freightLine["productname"] = "Freight Tax line"; freightLine["productdescription"] = "Freight Tax line"; freightLine["tax"] = new Money(10.00); service.Create(freightLine);
Here is the code I use to delete the same line from salesorderdetail if freight is either 0 or not present at all
if (freightLineExists) // if freight line exists then delete it as freight is not available anymore { tracer.Trace("freight exists"); tracer.Trace("Freight ID = "+ ec.Entities[freightLineNumber].Id); service.Delete(ec.Entities[freightLineNumber].LogicalName, ec.Entities[freightLineNumber].Id); }
*This post is locked for comments