Microsoft Dynamics 365 Blog

[Update 2012-06-21]  As mentioned earlier, the 2012 version of the support class has a different issue than the two mentioned here.  The good news is that it is much more simple to add an item to a transaction in the Blank Operation for 2012; you don’t need to use the support class at all.  One line of code does it for you:

            Application.RunOperation(PosisOperations.ItemSale, “0110”);


Or you can send in the item number from the Parameter defined on the Blank Operation button:

            Application.RunOperation(PosisOperations.ItemSale, operationInfo.Parameter);



As I mentioned in my previous article about the Blank Operation, there are a couple issues with the support classes provided with the blank operation.  Specifically, there are two bugs in ItemSale.cs.

The ItemSale.cs file contains the ItemSale() class.  This class provides a quick way to add items to the transaction via code.  To call the class you would use code similar to the following:

            ItemSale itemSale = new ItemSale();
itemSale.SellItem(ref posTransaction, “F-100006”, 2);

Fix 1:

The first issue happens if you are adding an item to a brand new transaction using this method.  When creating a new transaction, a “blank” customer needs to be added otherwise the tax engine will not calculate taxes properly.  Add the bolded lines of code to correct the issue:

                posTransaction = new RetailTransaction […]

                // initialize with empty/blank customer
                LSRetailPosis.Transaction.Customer customer = CustomerSystem.GetEmptyCustomer();
((RetailTransaction)posTransaction).Customer = customer;
((RetailTransaction)posTransaction).InvoicedCustomer = customer;
TransactionSystem transSystem = new TransactionSystem(posTransaction);

Fix 2:

The second problem is due to the way that the BarCode object gets initialized which could cause an unhandled exception downstream.  The simple fix here is to comment out the two lines of code that initialize the object and always send a null value instead:

            // Creating a barcode info object with the item ID
            //BarcodeInfo barCodeInfo = new BarcodeInfo();
            //barCodeInfo.BarcodeId = itemID;

BarcodeInfo barCodeInfo = null;

If you plan on programmatically adding items to the transaction using this method, these two fixes should help you out.

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!