Hi There,
I'm struggling some hours now of adding a "invoice"detail record to my invoice though code.
I know that this is possible, as I already found some good material to work with:
--> Create, QuoteDetail entity methods, CreateRequest(),...
But I'm just not able to add my DetailPos Item.
Here is my code of how I'm trying it:
First loading the invoice:
using (OrganizationServiceProxy organizationProxy = CRMLoginHelper.GetProxy(_organisationUrl, _userName, _password, _domain))
{
String strInvoiceNumber = "20150024";
String strProductId = "c2807776-f7ad-e411-a7b9-d89d67640040";
ISECRMBaselibrary.ISEInvoice xInvoice= new ISECRMBaselibrary.ISEInvoice(organizationProxy);
xInvoice.LoadBy_Iseid(strInvoiceNumber);
xInvoice.AddPos(strProductId, "Test Titel", "Testbeschrieb");
}
}
As you can see I'm getting the Invoice at: LoadBy_Iseid() this gives me the correct invoice. Than in the AddPos() Method:
public void AddPos(String ProductId, String Title, String Description)
{
Entity detailPos = new Entity(InvoiceDetailEntityName);
Entity Product = GetProduct(ProductId);
Guid UomId = Utilities.GetEntityRefernceId(Product, "defaultuomid");
Utilities.SetEntityRefernceId(detailPos, "invoiceid", InvoiceDetailEntityName, m_invoice.Id);
Utilities.SetEntityRefernceId(detailPos, "productid", ProductEntityName, Product.Id);
Utilities.SetEntityRefernceId(detailPos, "uomid", ProductEntityName, UomId);
Guid newPosId = m_organizationService.Create(detailPos);
}
First I'm creating the detailPos Entity for loading the attributes later. Than I'm getting my Product which I want to add to the InvoiceDetail Position. Than I fill the attibutes of the product and invoice to my invoiceDetail Entity. At least I try to .Create() my detailPos entity?
I just wanted to ask if that is the correct way of doing this or is there any better / easier way?