Microsoft Dynamics AX Support

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

Calling the LedgerPurchaseInvoice Service in AX 2012

Calling the LedgerPurchaseInvoice Service in AX 2012

Rate This
  • Comments 4

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;
           

            }

 

Leave a Comment
  • Please add 8 and 8 and type the answer here:
  • Post
  • Hi friend, This query is regarding AIF where I import data from an xml file in Ax 12 using file system adapter. I have a custom table say MetroTable with 4 fields <ID(pk),Name,Date,Remarks>.  I have created query, AIF classes (Service class, Axd class, AXBC class) and configured the inbound port. I can successfully import data from xml file in Ax using “Create” service operation and response xml file also gets created afterwards. All these runs in AIF batch job or can be run directly.

    Now, during my import,  I wanted to assign a field  value of “Remarks”  or want to manipulate other values. I tried writing few code in Axd class in prepareForSaveExtended() method or prepareForSave() method, but nothing happens. I also did some modification in AXBC class in the method setTableFields(), initRecords(), but again nothing changes after import. It only imports the data as specified in the xml file.

    I tried to debug as well, but the break point never activate in those classes. Looks like, those classes never called during data imort from xml. I know I am going wrong somewhere 

    Basically, what I am looking for, I want to do some insert/update in other tables or objects based on what I am importing from xml file using AIF file system adapter.

    Please help to comprehend me this. Thank you.

  • I would debug your class.  In 2012 services run as IL code, as do classes that run in batch that's why your breakpoints in the X++ code editor aren't getting hit.  To debug managed code you need to use the VS debugger and attach to the Ax32Serv.exe.  Have a look here for info on how to debug:

    msdn.microsoft.com/.../gg860898.aspx

  • Hi Guys,

    Please let me know if you got any error related to Invoice Date?

    Regards.

  • I don't see an invoice date on the header or lines entities.  I do see an InvoiceReleaseDate field on the journal line entity.  If that is the one you are trying to set it is a UtcDateTime field in AX which means you need to set it up more than you would for other dates.  Something like this:

               AxdExtType_InvoiceReleaseDate invoiceDate = new AxdExtType_InvoiceReleaseDate();

               invoiceDate.localDateTime = DateTime.Now;

               invoiceDate.localDateTimeSpecified = true;

               invoiceDate.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;

               journalLine.InvoiceReleaseDate = invoiceDate;

Page 1 of 1 (4 items)