Monday, December 15, 2014

Create Counting Journal in AX 2012 R2 via C# (Document Services)

Hi There,

Hi, I'd like to show some C# code that will create a Counting journal in AX 2012 R2.


I will be using the InventCountingJournalService service that already ships with AX 2012 R2.

This is a very low cost-high reward approach for the customers.

Let's start:


1- Create a Service Group








2- Add the InventCountingJournalService to the Service Group

3- Deploy the Service Group. This will output the following.








4- Get the WSDL URI from the inbound ports form.





5- Go to Visual Studio, create a new windows form project, add a button and double click the button to create a button event. 


6- Right - Click the Service References and choose Add Service Reference.





7 - Past the WSDL URI and click GO





8- Give your service a name i.e. InventCountingJournnal 

9 - Write the following code and test. 


 private void InventCountingJournal()

 {
            InventCountingJournal.CallContext callContext = new InventCountingJournal.CallContext();

            InventCountingJournal.CountingJournalServiceClient servClient = new  InventCountingJournal.CountingJournalServiceClient();


            InventCountingJournal.AxdCountingJournal countJournal = new InventCountingJournal.AxdCountingJournal();


            InventCountingJournal.AxdEntity_InventJournalTable journalHeader = new InventCountingJournal.AxdEntity_InventJournalTable();


            //Header

            callContext.Company = "CEU";
            journalHeader.JournalNameId = "CountJour";
            journalHeader.Description = "Counting Journal";
            //Header

            //lines

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

            journalLines.ItemId = "12345";

            journalLines.Qty = 50;
            journalLines.TransDate = DateTime.Now;

            InventCountingJournal.AxdEntity_InventDim inventDim = new InventCountingJournal.AxdEntity_InventDim();


            inventDim.InventBatchId = "3";

            inventDim.InventLocationId = "1";
            inventDim.InventSiteId = "3";

            journalLines.InventDim = new InventCountingJournal.AxdEntity_InventDim[1] { inventDim };


            //Lines


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


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


            servClient.create(callContextcountJournal);

 }


You can test this by clicking the button, and calling this method. A new counting journal would be created in AX. Then, you can either have a batch posting all the journals or simply have a user doing it manually. 


That's all for now!