Transaction Scope with Dataset Model Classes
 
Forums / SmartComponent Library - Developer Forum / Transaction Scope with Dataset Model Classes

Transaction Scope with Dataset Model Classes

5 posts, 1 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    03 Apr 2019
    Link to this post
    We have a BE with many tables. We use this for our point of sale transaction processing logic where we are parsing our electronic journal ("EJ") and creating records in TT's. When we are done parsing the "EJ" we then want to update the DB from the TT. In our existing POS module we scope the DB update as one DB transaction. We either want all the tables to be updated or none.

    How would we go about doing this with our Dataset Model class?

     I have tried

    /* Roger Blanchard / Osprey Retail Systems Apr 2, 2019
        Enable tracking changes 
    */
       
    oGeneralTotal:TrackingChanges = TRUE.

    // find an update record

    oGeneralTotal:NewFilter(oTransactionTotals:PostingDate,
                                        "D",
                                        oTransactionTotals:CashierNum,
                                        "").
                              
    oGeneralTotal:TrackingChanges = TRUE. 
       
    IF NOT oGeneralTotal:GeneralTotal:Available THEN
    DO:
        oGeneralTotal:GeneralTotal:Create().
        oGeneralTotal:GeneralTotal:SaleDate  = oTransactionTotals:PostingDate.
        oGeneralTotal:GeneralTotal:Period  = "D".
        oGeneralTotal:GeneralTotal:CashierNum = oTransactionTotals:CashierNum.
        oGeneralTotal:GeneralTotal:RegNum  = "". 
    END. 

    // Update addl fields here 

    // find an update another record here which may or may not be the same table
    // when we fetch the tracking changes will be turned off by default.
    // how do we save the changes from above in the TT and then send the entire batch of changes
    / to the backend


    // now savechanges
    oGeneralTotal:SaveChanges().


  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    03 Apr 2019 in reply to Roger Blanchard
    Link to this post
    Are all those temp-tables in the same business entity? In that case, just do a single SaveChanges in the end. 

    Alternatively, wrap the whole code in a DO TRANSACTION block. 
  3. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    03 Apr 2019 in reply to Mike Fechner
    Link to this post
    Hey Mike...thanks for the response. 

    Yes, they are all in the same BE. Right now I have the DO TRANSACTION wrapping it.

    I was trying to use the SaveChanges at the end but it looked like only the last change made it into the DB.

    For example,

    I want to create/update a record in table 1. I use the NewFilter in the dataset model class to fetch the record. I set tracking changes = true and then I create/update.

    I then want to create update another record in table 1 (monthly record versus daily) or create/update a record in a different table. I set tracking changes = true and then create /update.

    I then want to call SaveChanges

    So, you are saying the above should work? If so I will give it another shot.

    thanks. 





  4. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    Answered
    03 Apr 2019 in reply to Roger Blanchard
    Link to this post
    No.It's not supposed to work, when you use the same Dataset Model to fetch data multiple times. 
  5. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    03 Apr 2019 in reply to Mike Fechner
    Link to this post
    That is what I thought...thanks.
5 posts, 1 answered