Microsoft Dynamics AX Support

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

Calling the InventTransferJournalService in AX 2012

Calling the InventTransferJournalService in AX 2012

Rate This
  • Comments 7

I received a question on how to call this service.  The code below creates an inventory transfer journal for me in the demo data:

TransferJournalServiceClient client = new TransferJournalServiceClient();

CallContext context = new CallContext();

           
context.Company = "ceu";

 

AxdTransferJournal journal = new AxdTransferJournal();

AxdEntity_InventJournalTable journalHeader = new AxdEntity_InventJournalTable();

journalHeader.JournalNameId = "ITrf";

 

AxdEntity_InventJournalTrans inventJournalTrans = new AxdEntity_InventJournalTrans();

inventJournalTrans.ItemId = "1000";

           

AxdEntity_InventDimIssue inventDimIssue = new AxdEntity_InventDimIssue();

inventDimIssue.InventSiteId = "2";

inventDimIssue.InventLocationId = "21";

inventJournalTrans.InventDimIssue = new AxdEntity_InventDimIssue[1] { inventDimIssue };

 

AxdEntity_InventDimReceipt inventDimReceipt = new AxdEntity_InventDimReceipt();

inventDimReceipt.InventSiteId = "1";

inventDimReceipt.InventLocationId = "11";

inventJournalTrans.InventDimReceipt = new AxdEntity_InventDimReceipt[1] { inventDimReceipt };

           

           
journalHeader.InventJournalTrans = new AxdEntity_InventJournalTrans[1] {inventJournalTrans };

           
journal.InventJournalTable = new AxdEntity_InventJournalTable[1] { journalHeader };

 try

{             
  client.create(context, journal);

}

catch (Exception e)

{               
string error = e.Message;

Console.ReadLine();

}

 

Leave a Comment
  • Please add 3 and 7 and type the answer here:
  • Post
  • How to create multiline journal (C#)?

  • All services work the same way, you just keep adding to the array of lines on the header object.  Here's an example that creates a sales order with two lines:

               SalesOrderServiceClient proxy = new SalesOrderServiceClient();

               CallContext context = new CallContext();

               context.Company = "ceu";

               AxdSalesOrder salesOrder = new AxdSalesOrder();

               AxdEntity_SalesTable[] salesTables = new AxdEntity_SalesTable[1];

               AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();

               salesTable.CurrencyCode = "USD";

               salesTable.CustAccount = "1103";

               salesTable.ReceiptDateRequested = Convert.ToDateTime("2/1/2012");

               salesTable.Payment = "N060";

               salesTable.PurchOrderFormNum = "PO12345";

               AxdEntity_SalesLine salesLine = new AxdEntity_SalesLine();

               salesLine.ItemId = "1000";

               salesLine.SalesQty = 1;

               salesLine.SalesUnit = "ea";

               AxdEntity_SalesLine salesLine2 = new AxdEntity_SalesLine();

               salesLine2.ItemId = "1000";

               salesLine2.SalesQty = 55;

               salesLine2.SalesUnit = "ea";

               salesTable.SalesLine = new AxdEntity_SalesLine[2] { salesLine, salesLine2 };

               salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };

               try

               {

                   proxy.create(context, salesOrder);

               }

               catch (Exception e)

               {

                   throw e;

                   Console.ReadLine();

               }

  • Thank you very much!

  • using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using CrearOV.ServiceReference1;

    // Add a using statement for the service reference.

    using System.Collections;

    namespace ConsumeSalesOrderService

    {

       class Program

       {

           static void Main(string[] args)

           {

               int i = 2;

               int count = 0;

               AxdEntity_SalesLine[] salesLine = new AxdEntity_SalesLine[2];

               // Instantiate an instance of the service client class.

               SalesOrderServiceClient proxy = new SalesOrderServiceClient();

               // Create an instance of the document class.

               AxdSalesOrder salesOrder = new AxdSalesOrder();

               // Create instances of the entities that are used in the service and

               // set the needed fields on those entities.

               AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();

               salesTable.CurrencyCode = "USD";

               salesTable.CustAccount = "1101";

               salesTable.DeliveryDate = Convert.ToDateTime("2/14/2010");

               salesTable.Payment = "N060";

               salesTable.PurchOrderFormNum = "PO";

               //AxdEntity_SalesLine[] salesLine3 = new AxdEntity_SalesLine[2];

                salesTable.SalesLine = new AxdEntity_SalesLine[2];

               while (count < i)

               {

                       //salesLine = new AxdEntity_SalesLine[count];

                       salesLine[count] = new AxdEntity_SalesLine();

                       salesLine[count].ItemId = "2727";

                       salesLine[count].SalesQty = 88+count;

                       salesLine[count].SalesUnit = "Pcs";

                       //AxdEntity_SalesLine[] salesLines = salesLine;

                   //AxdEntity_InventDim inventDim = new AxdEntity_InventDim();

                   //inventDim..configId = "HD";

                   //inventDim.InventColorId = "01";

                   //inventDim.InventSizeId = "42";

                   // Add the sub-entity instances to their parent entities as an array

                   // of the sub-entity type.

                   //salesLine.InventDim = new AxdEntity_InventDim[1] { inventDim };

                   //salesTable.SalesLine =   new AxdEntity_SalesLine[] { salesLine };

                   salesTable.SalesLine[count] = new AxdEntity_SalesLine();

                   salesTable.SalesLine[count] = salesLine[count];

                   count++;

               }

               foreach (AxdEntity_SalesLine salesLines in salesLine)

               {

                   decimal itemId = salesLines.SalesQty;

                   Console.WriteLine("Item Id    : " + itemId);

               }

               salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };

               try

               {

                   // Call the create method on the service passing in the document.

                   EntityKey[] returnedSalesOrderEntityKey = proxy.create(salesOrder);

                   // The create method returns an EntityKey which contains the ID of the sales order.

                   EntityKey returnedSalesOrder = (EntityKey)returnedSalesOrderEntityKey.GetValue(0);

                   Console.WriteLine("The sales order created has a Sales ID of " + returnedSalesOrder.KeyData[0].Value);

                   Console.ReadLine();

               }

               catch (Exception e)

               {

                   Console.WriteLine(e.ToString());

                   Console.ReadLine();

               }

           }

       }

    }

  • I can create an Inventory Transfer based on the above code but how do I Post it?

    Setting the AxdEntity_InventJournalTable properties does nothing.

    .Posted = AxdExtType_JournalPosted.Yes

    .PostedSpecified = True

  • Hi Russ,

    You won't be able to post the service using any of the standard operations on it.  That is true for all of the services I'm aware of that create transactions.  The operations that ship with out-of-the-box document services are create, read, update, delete, find and more types of reads.  They don't have functions built in them to post.  To get that functionality you'd need to either create a new service that isn't a document service and is rather a custom service or you'd have to modify the existing service and add a new operation to it.  

    If you are working in 2012, custom services are pretty easy to create so I wouldn't shy away from them.  You pretty much just create an X++ class that contain methods to do whatever functionality you need (in this case posting) and add attributes to the class and method so they can be exposed for external consumption in a service.  Have a look here for more details:

    msdn.microsoft.com/.../hh509052.aspx

  • You can find a walkthrough how to create an AIF service to post a transfer journal here: www.discipline.org.ua/.../Transfer_journal_posting_web_service_AIF_AX_2012R2.htm

Page 1 of 1 (7 items)