Forums / Developer Forum / More Validation Questions

More Validation Questions

11 posts, 0 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    86 posts
    Registered:
    29 Jun 2018
    09 Jan
    Link to this post
    I have a BE designed with the following tables;
    PurchaseOrder
    PoLine
    HistoryTots

    On the client side I have a form with the following;
    SmartToolbar
    SmartDataBrowse of PurchaseOrders
    SmartViewer to add/update PurchaseOrder

    All is good. I can create PurchaseOrder records, update, delete etc. My validation is working correctly in ValidateData.

    If you then double-click the SmartDataBrowse I open another form that will be used to add PoLine records. It has the following;
    Smarttoolbar
    SmartViewer

    All is good. I can create PoLine records, update, delete, etc. Most of my validation is working. I have a few issues I am not sure how to resolve except for just using the ABL FOR EACH.

    Issue #1

    In the BE:ValidateData I need to reference the parent PurchaseOrder record to determine what type of Order.

    If I use a FOR FIRST PurchaseOrder WHERE PurchaseOrder.OrderNum = ePoLine.OrderNum I can get what I need.

    If I use a FOR FIRST ePurchaseOrder WHERE ePurchaseOrder.OrderNum = ePoLine.OrderNum there is no record available.

    If I create a FetchDataRequest object and use FetchData in the BE I get an error "MERGE-CHANGES run on original table ePurchaseOrder that does not match the ORIGIN-HANDLE in the GET-CHANGES table ePurchaseOrder (11923)

    What is the best way for me to reference the PurchaseOrder parent record in ValidateData?

    Issue #2

    This is similar but in the PurchaseOrderDataClass:ePoLineCreateEndTrans. When we add a PoLine we want to update the PurchaseOrder parent record with the PoLine.Amount. What is the best way to do this?

  2. Mike Fechner
    Mike Fechner avatar
    62 posts
    Registered:
    14 Sep 2016
    11 Jan in reply to Roger Blanchard
    Link to this post
    Regarding question 1. 

    You're probably using two different SmartBusinessEntityAdapter instances in that screen. On for ePurchaseOrder and one for ePoLine. In that case, the client does only send modified ePoLine record(s) to the backend on save. As the PoLine-SmartBusinessEntityAdapter is not aware of any ePurchaseOrder records. It does not have them. 

    Option one:

    You can resolve this by using a SmartDatasetChildAdapter instead for the ePoLine table. 

    The SmartBusinessEntityAdapter would need to be configured like this to take care about the ePoLine table as well:

    EntityTable: ePurchaseOrder
    EntityView: ePoLine
    EntityJoin: no (this is done by unchecking the Use In Frontend Query in the Tables dialog)

    The SmartDatasetChildAdapter would use the smartBusinessEntityAdapter1 as the LinkDataSource and use ePoLine as the EntityTable.

    Now, when the user edit's an ePoLine, the unmodified parent record will be send to the client too.







  3. Mike Fechner
    Mike Fechner avatar
    62 posts
    Registered:
    14 Sep 2016
    11 Jan in reply to Roger Blanchard
    Link to this post
    Option two:

    Let the Business Entity fetch the missing records from the DB:

    https://documentation.consultingwerkcloud.com/display/SCL/Release+Notes+2018-12-09#ReleaseNotes2018-12-09-SCL-1975BusinessEntitynowprovidesanewinternalmethodtopopulatetherelatedrecordsofagiventemp-tablerecord

    So in the Business Entity, call THIS-OBJECT:FetchRelatedRecords (BUFFER ePoLine:HANDLE, "ePurchaseOrder").
    Last modified on 11 Jan 2019 03:01 by Mike Fechner
  4. Mike Fechner
    Mike Fechner avatar
    62 posts
    Registered:
    14 Sep 2016
    11 Jan in reply to Mike Fechner
    Link to this post
    Issue 2: 

    Use any of Option 1 or Option 2, set the TRACKING-CHANGES on ePurchaseOrder and update the record in ValidateData.

    You'll probably have to fetch all ePoLine records though. So that should be doable using 

    THIS-OBJECT:FetchRelatedRecords (BUFFER ePoLine:HANDLE, "ePurchaseOrder,ePoLine").
  5. Roger Blanchard
    Roger Blanchard avatar
    86 posts
    Registered:
    29 Jun 2018
    11 Jan in reply to Mike Fechner
    Link to this post
    Mike,

    Issue 1:

    You are exactly right. I am using a different  adapter for ePoLine.

    Let me review the two options and see what works best. I am thinking Option 1 would be best.

    Issue 2:

    Once I get Issue 1 resolved I will look at this.

    Thank you!!
  6. Roger Blanchard
    Roger Blanchard avatar
    86 posts
    Registered:
    29 Jun 2018
    11 Jan in reply to Mike Fechner
    Link to this post
    Okay,

    Option1 will cause the RetrieveData of the PurchaseOrderAdapter to fetch not only the PurchaseOrder records but the PoLine records at the same time so more data initially coming down the wire.

    Option2 basically stays the same as what I am doing except I can use the FetchRelatedRecords in the BE to fetch the parent record which in this case is ePurchaseOrder. Can the ePurchaseOrder record be updated as well? I would think this would be much more efficient. 

    I think I would like to try Option2 but it appears that was just added recently. I went to grab the latest SCL and I cannot get into the ESD site. I sent you an email on this.

    thanks.

  7. Roger Blanchard
    Roger Blanchard avatar
    86 posts
    Registered:
    29 Jun 2018
    14 Jan in reply to Mike Fechner
    Link to this post
    Mike,

    I am trying to get THIS-OBJECT:FetchRelatedRecords to work. If I put the call in the BE in my FOR EAC ePoLine loop I do have access the ePurchaseOrder in the BE as well as the PurchaseOrderDataAccess.cls. I am trying to update the ePurchaseOrder record in my PurchaseOrderDataAccess:ePoLineCreateBeginTrans and while the TT record will change it does not get saved in the DB. I do have TRACKING-CHANGES = TRUE. Can this be done in the data access class or does it have to be done in the BE?

    This is in my BE;

     FOR EACH ePoLine WHERE ROW-STATE (ePoLine) <> ROW-UNMODIFIED ON ERROR UNDO, THROW:
             
        THIS-OBJECT:FetchRelatedRecords (BUFFER ePoLine:HANDLE, "ePurchaseOrder").

    END.

    I am trying this in my data access class but the updates to ePurchaseOrder do not make it to the DB.

    IF AVAILABLE ePoLine THEN
    DO ON ERROR UNDO, THROW:

       IF AVAILABLE ePurchaseOrder THEN
       DO:
           TEMP-TABLE ePurchaseOrder:TRACKING-CHANGES = TRUE.

            ASSIGN
                ePurchaseOrder.PoAmt = ePurchaseOrder.PoAmt + ePoline.LineAmt - ePoline.DiscAmt
                ePurchaseOrder.OpenAmt = ePurchaseOrder.OpenAmt + ePoline.LineAmt  - ePoline.DiscAmt
                ePurchaseOrder.DiscAmt  = ROUND(ePurchaseOrder.PoAmt  * ePurchaseOrder.DiscPerc  / 100,2). 
       END. 

    END.
  8. Mike Fechner
    Mike Fechner avatar
    62 posts
    Registered:
    14 Sep 2016
    16 Jan in reply to Roger Blanchard
    Link to this post
    I would code that in the Business Entity. As it's business logic. 

    Where in the Data Access class is that coded? 
  9. Roger Blanchard
    Roger Blanchard avatar
    86 posts
    Registered:
    29 Jun 2018
    16 Jan in reply to Mike Fechner
    Link to this post
    I have it in ePoLineCreateEndTrans, ePoLineModifyEndTrans.

    This code seems to work.

    IF AVAILABLE ePurchaseOrder THEN
    DO:
        TEMP-TABLE ePurchaseOrder:TRACKING-CHANGES = TRUE.
        
        ASSIGN
         ePurchaseOrder.PoAmt = ePurchaseOrder.PoAmt + ePoline.LineAmt - ePoline.DiscAmt
         ePurchaseOrder.OpenAmt = ePurchaseOrder.OpenAmt + ePoline.LineAmt  - ePoline.DiscAmt
         ePurchaseOrder.DiscAmt  = ROUND(ePurchaseOrder.PoAmt  * ePurchaseOrder.DiscPerc  / 100,2)
         ePurchaseOrder.Exported = FALSE /* toggle Exported field so user knows they need to send again */
         .
        
        /* Roger Blanchard / Osprey Retail Systems Jan 15, 2019
         This seems to work
        */  
        THIS-OBJECT:SaveBuffer(BUFFER ePurchaseOrder:HANDLE).
        
       END.
  10. Mike Fechner
    Mike Fechner avatar
    62 posts
    Registered:
    14 Sep 2016
    16 Jan in reply to Roger Blanchard
    Link to this post
    Changes to the temp-tables in the ....ModifyEndTrans are happening past writing changes to the DB.

    I strongly suggest to code this in the Business Entity. ValidateData or SaveChanges. 
  11. Roger Blanchard
    Roger Blanchard avatar
    86 posts
    Registered:
    29 Jun 2018
    5 days and 15 hours ago in reply to Mike Fechner
    Link to this post
    Thanks Mike...I will take a look at this.

11 posts, 0 answered