Hi, I am trying to create a new invoice from the existing invoice and add the products from the existing invoice as well. The issue is it is duplicating products, I highlighted the products that I need. Please help
// getting old invoice details
var oldInvoiceDetails = from o in svcContext.InvoiceDetailSet where o.InvoiceId.Id == entityRef.Id select o;
// add everyting from old invoice details to new invoice detail
foreach (var oldinv in oldInvoiceDetails)
{ InvoiceDetail invdetail = new InvoiceDetail();
invdetail.InvoiceId = new EntityReference(Invoice.EntityLogicalName, invoiceId);
invdetail.ParentBundleId = oldinv.ParentBundleId ?? null;
invdetail.ProductId = oldinv.ProductId; invdetail.UoMId = oldinv.UoMId;
invdetail.Quantity = oldinv.Quantity;
invdetail.ExtendedAmount = oldinv.ExtendedAmount;
service.Create(invdetail);
}
*This post is locked for comments