Friday, August 23, 2013

Create a Transfer Journal using AX 2012 R2 Document Services and C#


Hi there,
On this post I would like to share some C# code to create a Transfer Journal using C#. I have written a few post in the past about services and they will help you understand how to create a service, service groups, deployment, etc.
Create Counting Journals
How to choose the right service
AX 2012 Services and AIF
Services Types
Creating a service in AX 2012
Back to the creation of a Transfer Journal with C#, this is an interesting code as we need to instantiate two different instances of the InventDim Table; InventDimIssue and InventDimReceipt.
InventDimIssue can be thought as the From values and InventDimReceipt can be thought as the To values (i.e. From Warehouse ==> To Warehouse).
In addition, another interesting point is that AX uses the InventJournalTable and InventJournalTrans for all the inventory journal entries, and we specified, in C#, which entity (AXD) will be using.
The following is the code:
private void InventTransferJourTest()
            InventTransferJournal.CallContext callContext = new InventTransferJournal.CallContext();

            InventTransferJournal.TransferJournalServiceClient servClient = new InventTransferJournal.TransferJournalServiceClient();

            InventTransferJournal.AxdTransferJournal transjournal = new InventTransferJournal.AxdTransferJournal();

            InventTransferJournal.AxdEntity_InventJournalTable journalheader = new InventTransferJournal.AxdEntity_InventJournalTable();

            callContext.Company = "CEU";
            journalheader.JournalNameId = "TransferJourId";
            journalheader.Description = "Transfer Journal";
            //End header

            InventTransferJournal.AxdEntity_InventJournalTrans journalLines = new InventTransferJournal.AxdEntity_InventJournalTrans();

            journalLines.ItemId = "123456";
            journalLines.Qty = 45;
            journalLines.TransDate = DateTime.Now;

            InventTransferJournal.AxdEntity_InventDimIssue inventDimIssue = new InventTransferJournal.AxdEntity_InventDimIssue();

            inventDimIssue.InventBatchId = "RUT";
            inventDimIssue.InventLocationId = "21";
            inventDimIssue.InventSiteId = "1";

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

            InventTransferJournal.AxdEntity_InventDimReceipt inventDimReceipt = new InventTransferJournal.AxdEntity_InventDimReceipt();

            inventDimReceipt.InventSiteId = "2";
            inventDimReceipt.InventLocationId = "11";
            inventDimReceipt.InventBatchId = "RSR";

            journalLines.InventDimReceipt = new InventTransferJournal.AxdEntity_InventDimReceipt[1] { inventDimReceipt };
            //End Lines

            journalheader.InventJournalTrans = new InventTransferJournal.AxdEntity_InventJournalTrans[1] { journalLines };

            transjournal.InventJournalTable = new InventTransferJournal.AxdEntity_InventJournalTable[1] {journalheader};

                servClient.create(callContext, transjournal);
            catch (Exception e)

 That's all for today and stay tuned as in the next few weeks I will be talking about TFS and how to work with AX 2012 in a way that we utilize the TFS server to its max capacity.

Have a great weekend!


  1. Hi, perhaps I could ask for a favour.
    Im trying to implement some C# code to call a document service i created based on the PurchTable and Purch Line Tables

    The idea is to consume data on a light switch screen and create a purchase order in Ax2012.
    Ive used the transfer journal example to start on my code, but cant seem to get the iteration right.

    Could you look into posting a class that posts an order with 3 lines.


    1. Hi,

      I have a sale order code. Just go to AX and in the code replace the entity.

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using ConsumeSalesOrderService.SalesOrder;
      // Add a using statement for the service reference.
      using System.Collections;

      namespace ConsumeSalesOrderService
      class Program
      static void Main(string[] args)
      // 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 salesLine = new AxdEntity_SalesLine();
      salesLine.ItemId = "1001";
      salesLine.SalesQty = 88;
      salesLine.SalesUnit = "ea";

      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[1] { salesLine };
      salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };

      // 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);

      catch (Exception e)


Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!