Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
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.

Categories:
  • 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans