Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

Add item to new transaction

Posted on by 505

Good day.

i am hoping that someone is able to assist me with an issue that i am facing.

i need to add an item to a transaction from code in the BlankOperations project, the issue i am having is that if it is a new transaction then the code fails. i read the following post that states there is a bug that exists that adding an item to a new transaction has an issue because a new blank customer will need to be added first. (https://cloudblogs.microsoft.com/dynamics365/no-audience/2012/04/22/ax-for-retail-two-bug-fixes-for-the-blank-operation-sell-item/)

This makes sense, however i am not sure where this code fix is supposed to placed. i have tried a few things to try and set a blank customer but that too does not seem to work. i have tried a few variations of code but neither seem to work.

var emptyCustomer = CustomerSystem.GetEmptyCustomer();
LSRetailPosis.Transaction.Customer BlankCustomer = emptyCustomer as LSRetailPosis.Transaction.Customer;
Customer.Customer cc = new Customer.Customer();

cc.AddCustomerToTransaction(BlankCustomer, posTransaction);

var emptyCustomer = CustomerSystem.GetEmptyCustomer();
LSRetailPosis.Transaction.Customer BlankCustomer = emptyCustomer as LSRetailPosis.Transaction.Customer;

((RetailTransaction)posTransaction).Customer = BlankCustomer;
((RetailTransaction)posTransaction).InvoicedCustomer = BlankCustomer;

                     

ITransactionSystem transSys = this.Application.BusinessLogic.TransactionSystem;
transSys.LoadTransactionStatus(posTransaction);

var emptyCustomer = CustomerSystem.GetEmptyCustomer();

LSRetailPosis.Transaction.Customer BlankCustomer = emptyCustomer as LSRetailPosis.Transaction.Customer;

Application.RunOperation(PosisOperations.CustomerAdd, BlankCustomer, posTransaction);

what i am trying to achieve is to add items to the transaction. if there is an existing item in the transaction or a customer has been set to the transaction (from default functionality) then adding an item either by using

Application.RunOperation(PosisOperations.ItemSale, "123");

or by using

LSRetailPosis.POSProcesses.ItemSale iSale = new LSRetailPosis.POSProcesses.ItemSale();


iSale.OperationID = PosisOperations.ItemSale;
iSale.OperationInfo = new LSRetailPosis.POSProcesses.OperationInfo();
iSale.Barcode = "123";
iSale.OperationInfo.NumpadQuantity = 1;
iSale.POSTransaction = (PosTransaction)posTransaction;


iSale.RunOperation();

works correctly and i am able to continue and add my items programmatically. i think its due to the fact that a new transaction object may be null, so my thinking is to create or instantiate a new retail transaction object if one does not already exist. i have tried doing this as well but have had no luck yet.

any assistance in this regard would be appreciated.

  • RE: Add item to new transaction

    Thanks for the update - good to hear that you got it working.

  • Suggested answer
    B.W Profile Picture
    B.W 505 on at
    RE: Add item to new transaction

    Good day Shane.

    i have managed to resolve my issue.

    i am not sure if there is an issue with running the Application.RunOperation(PosisOperations.ItemSale, "123"); in my Blank Operation as i was always getting an error.

    i moved the logic and code to another helper class in a different project and added the above code and it now adds the items to the transaction without any issues.

    Thank you once again for taking the time to reply and for your assistance.

  • B.W Profile Picture
    B.W 505 on at
    RE: Add item to new transaction

    Good day Shane.

    thank you for your response.

    Yes i am using 2012.

    when i run

    Application.RunOperation(PosisOperations.ItemSale, "123");

    the item is added to the transaction, however i get an error immediately.

    this is the error below from the even viewer.

    LSRetailPosis.POSProcesses.POSApp: System.InvalidOperationException: Stack empty.
       at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
       at System.Collections.Generic.Stack`1.Peek()
       at LSRetailPosis.POSProcesses.POSApp.RunOperationInternal(PosisOperations operationID, Object extraInfo, OperationInfo operationInfo, PosTransaction newPosTransaction)

    i have even tried running the RunOperation by passing in the posTransaction Object but that too does not seem to work.

    if however i add any other item to the transaction first and then run the Blank Operation with the one-liner then i do not receive the error.

  • Verified answer
    RE: Add item to new transaction

    If you're using AX 2012, the bold part of that blog post should be the most relevant.  You shouldn't have to do the majority of what's written in there.  The one-liner with the RunOperation and .ItemSale should work regardless of whether the transaction is brand new or not.  It should do everything it needs to do for a new transaction object and create one if it doesn't exist.

    So I believe you're on the right track - it's been quite a while since I've worked on any EPOS development, though, so I can't confirm it right now.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans