Forums / SmartComponent Library - Developer Forum / BusinessEntity - Update Additional Records

BusinessEntity - Update Additional Records

3 posts, 1 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    343 posts
    Registered:
    29 Jun 2018
    05 Jan
    Link to this post
    We have a use case where if a field is changed in a record we need to update addl records.

    For example, we have a field called Upc.IsPrimary. When this field is toggled to True we need to toggle all other Upc record for an item to False.

    I am wondering the best way to handle this. In our current framework we use;

    FOR EACH Upc WHERE Upc.ItemNum = eUpc.ItemNum
        AND Upc.PackNum = eUpc.PackNum
        AND Upc.UpcNum NE eUpc.UpcNum: 
        Upc.IsPrimary = FALSE.
    END.

    I have read the following and this is similar but different. I have code where I am reading the addl Upc records using a different instance of the BE. How would I merge these updates into the PDS used by the original BE? 


    https://consultingwerk.atlassian.net/wiki/spaces/SCL/pages/8093734/Knowing+when+a+new+record+is+a+copy+of+another+record+while+saving+the+new+record+on+the+backend
  2. Mike Fechner
    Mike Fechner avatar
    263 posts
    Registered:
    14 Sep 2016
    Answered
    05 Jan
    Link to this post
    There is no simple and no single true answer to this question.

    In most cases updates to additional records should be done in a Business Task wrapping the update in a single transaction - or in the Data Access class. This all depends on nuances of the use case.

    In this case, where other records from the same table need to be updated in the way you have described, I would implement that as part of the Data Access class straight on the Database tables. Unless you need those records during the update in the ProDataset, there's probably no added value to read those records into the ProDataset just to update a logical status field.

    The challenging bit with this technique however is that this may cause that the view of those additional records table kept in the ProDataset on the client gets purposely out of sync with the database records. If you'd attempt to update one of those additional records later, the ProDataset SAVE-ROW-CHANGES method may throw the error that the current recrdo has been changed to by another user. This may or may not be an issue for you.

  3. Roger Blanchard
    Roger Blanchard avatar
    343 posts
    Registered:
    29 Jun 2018
    05 Jan in reply to Mike Fechner
    Link to this post
    Thanks Mike...that is what I figured but I figured I would run it by the experts.

    I enabled 'RefetchCurrentRowOnUpdate' for the viewer as to get the latest.

    Thanks again.
3 posts, 1 answered