How to create Purchase Invoice through AIF using LedgerPurchaseInvoiceService

Hi…All,

I m trying to create a purchase invoice in ax 2012.

i m using LedgerPurchaseInvoiceService for creating purchase invoice. It allows me to create Invoice Journal only and the entry goes in LedgerJournalTable. But when i m trying to create lines into that invoice journal then it doesn’t allow me to create line.

The line entry will be goes into the LedgerJournalTrans table.

The below one is code for the same.

The exception is Invalid XML Document.

protected void cmdpurchinv_Click(object sender, EventArgs e)
{
CarDetails.PurchaseInvoiceService.PurchaseInvoiceServiceClient client = new PurchaseInvoiceService.PurchaseInvoiceServiceClient();
CarDetails.PurchaseInvoiceService.AxdPurchaseInvoice PurchInv = new PurchaseInvoiceService.AxdPurchaseInvoice();

CarDetails.PurchaseInvoiceService.CallContext callcontext = new PurchaseInvoiceService.CallContext();
CarDetails.PurchaseInvoiceService.EntityKey[] keys;
CarDetails.PurchaseInvoiceService.EntityKey key = new PurchaseInvoiceService.EntityKey();
CarDetails.PurchaseInvoiceService.KeyField fld = new PurchaseInvoiceService.KeyField();

CarDetails.PurchaseInvoiceService.AxdEntity_LedgerJournalTable1 ledgerJrnTable = new PurchaseInvoiceService.AxdEntity_LedgerJournalTable1();
ledgerJrnTable.JournalName = “APInv”;

CarDetails.PurchaseInvoiceService.AxdEntity_LedgerJournalTrans1 ledgerJrnTrans = new PurchaseInvoiceService.AxdEntity_LedgerJournalTrans1();

ledgerJrnTrans.CurrencyCode = “USD”;
ledgerJrnTrans.Invoice = “1111”;
ledgerJrnTrans.AmountCurCredit = 1000;
ledgerJrnTrans.Company = “ceu”;
ledgerJrnTrans.DocumentDate = System.DateTime.Today;

CarDetails.PurchaseInvoiceService.AxdType_MultiTypeAccount ledgerDim = new PurchaseInvoiceService.AxdType_MultiTypeAccount();
CarDetails.PurchaseInvoiceService.AxdType_DimensionAttributeValue dimAttValue = new PurchaseInvoiceService.AxdType_DimensionAttributeValue();
dimAttValue.Name = “Jason Zender”;
dimAttValue.Value = “9013”;
ledgerDim.Values = new PurchaseInvoiceService.AxdType_DimensionAttributeValue[] { dimAttValue };
ledgerJrnTrans.LedgerDimension = ledgerDim;

CarDetails.PurchaseInvoiceService.AxdEntity_HcmWorkerLineApprover worker = new PurchaseInvoiceService.AxdEntity_HcmWorkerLineApprover();
worker.PartyNumber = “76”;
ledgerJrnTrans.HcmWorkerLineApprover = new PurchaseInvoiceService.AxdEntity_HcmWorkerLineApprover[] { worker };

ledgerJrnTable.LedgerJournalTrans = new PurchaseInvoiceService.AxdEntity_LedgerJournalTrans1[] { ledgerJrnTrans };
PurchInv.LedgerJournalTable = new PurchaseInvoiceService.AxdEntity_LedgerJournalTable1[] { ledgerJrnTable };

keys = client.create(callcontext, PurchInv);
key = keys[0];
fld = key.KeyData[0];

lblcpj.Text = fld.Value;

}

Plz tell me if i m missing anything or i m giving any wrong values.

Thanks in advance.