Hi,
I'm trying to add a product to an invoice via plugin in CRM 2011, but the plugin gives an error. Inside the error there is the message: <Message>The parent id is missing.</Message>.
Here I create the invoice and it works fine:
Entity invoiceRecord = new Entity("invoice");
invoiceRecord["name"] = "Sample Invoice";
invoiceRecord["customerid"] = new EntityReference("account", regardingobjectidAccount);
invoiceRecord["pricelevelid"] = new EntityReference("pricelevel", PriceListGUID);
RegardingobjectidInvoice = service.Create(invoiceRecord);
And here I want to create the product, which should be related to the invoice above:
Entity invoiceProduct = new Entity("invoicedetail");
invoiceProduct["productid"] = new EntityReference("product", ProductGUID);
invoiceProduct["quantity"] = 1;
invoiceProduct["invoiceid"] =invoiceRecord.ToEntityReference();
invoiceProduct["UoMId"] = new EntityReference("UoM", UoMGUID);
service.Create(invoiceProduct);
In this line there is obviously an error:
invoiceRecord["invoiceid"] = invoiceRecord.ToEntityReference();
Can anybody help me with it?