Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support Teams Worldwide

Calling the LedgerPurchaseInvoice Service in AX 2012

I had a blog comment requesting that I demonstrate how to call the LedgerPurchaseInvoice service so here you go:

 

            //A purchase invoice created by this service = AP > Journals > Invoices > Invoice register

            //Think it depends on which journal name you set up under AP > Setup > AP Parameters > AIF

            //I have it set to APInvReg

            PurchaseInvoiceServiceClient client = new PurchaseInvoiceServiceClient();

            CallContext context = new CallContext();

           
            context.Company = “ceu”;

 

            AxdPurchaseInvoice purchInvoice = new AxdPurchaseInvoice();

            AxdEntity_LedgerJournalTable journalHeader = new AxdEntity_LedgerJournalTable();

           
            journalHeader.JournalName = “APInvReg”;

 

            AxdEntity_LedgerJournalTrans journalLine = new AxdEntity_LedgerJournalTrans();

           
            journalLine.AccountType = AxdEnum_LedgerJournalACType.Vend;

           
            journalLine.AccountTypeSpecified = true;

           
            journalLine.Company = “ceu”;

 

            AxdType_MultiTypeAccount account = new AxdType_MultiTypeAccount();

           
            account.Account = “1002”;

           
           account.DisplayValue = “1002”;

 

           
           journalLine.LedgerDimension = account;

           
           journalLine.DocumentDate = Convert.ToDateTime(“12/6/2011”);

           
           journalLine.Invoice = “1235”;

           
          journalLine.AmountCurDebit = 120;

           
          journalLine.AmountCurDebitSpecified = true;

  
          journalHeader.LedgerJournalTrans = new AxdEntity_LedgerJournalTrans[1] { journalLine };

           
          purchInvoice.LedgerJournalTable = new AxdEntity_LedgerJournalTable[1] { journalHeader };

            try

            {
                 client.create(context, purchInvoice);

            }

            catch (Exception e)

            {

               
                string error = e.Message;
           

            }