DatasetMovel Class with Relations
 
Forums / SmartComponent Library - Developer Forum / DatasetMovel Class with Relations

DatasetMovel Class with Relations

6 posts, 3 answered
  1. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    Answered
    07 Nov 2018
    Link to this post
    I have created a BE for my Item table with relations to the Totals and HistoryTots tables.

    If I do the following;

    oItem = NEW ItemDatasetModel ().
    oItem:ITEM:FillTotals   = TRUE.
    oItem:ITEM:FillHistoryTots  = TRUE.
    oItem:Item:Fill().

    I will get all my items with related records for Totals and HistoryTots.

    If I want to filter the HistoryTots should I be able to do the following;

    oItem = NEW ItemDatasetModel ().
    oItem:ITEM:FillTotals   = TRUE.
    oItem:ITEM:FillHistoryTots  = TRUE.

    / I want related record but only where the Period equals "M"
    oItem:HistoryTots:Filter:Period:EQ("M").

    oItem:Item:Fill().
  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    08 Nov 2018 in reply to Roger Blanchard
    Link to this post
    There is currently no way to use DatasetModels to provide a strong typed filter argument for multiple tables.

    Best you can do is probably this here:

    DEFINE VARIABLE oOrder AS OrderDatasetModel NO-UNDO .

    oOrder = NEW OrderDatasetModel() .
    oOrder:RetrieveData("eOrder,eOrderLine",
                        "for each eOrder where eOrder.Custnum = 1" + CHR (1) +
                        "for each eOrderLine where eOrderLine.LineNum = 2") .

    oOrder:UseDatasetQueries() .

    DO WHILE oOrder:Order:Available:
        IF oOrder:OrderLine:Available THEN
            MESSAGE oOrder:Order:CustNum SKIP
                    oOrder:Order:Ordernum SKIP (2)

                    oOrder:OrderLine:Ordernum SKIP
                    oOrder:OrderLine:Linenum
                VIEW-AS ALERT-BOX.
        ELSE
            MESSAGE oOrder:Order:CustNum SKIP
                    oOrder:Order:Ordernum SKIP

                VIEW-AS ALERT-BOX.

        oOrder:Order:GetNext().
    END.
  3. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    Answered
    08 Nov 2018 in reply to Mike Fechner
    Link to this post
    That will work...thanks.
  4. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    01 Dec 2018 in reply to Mike Fechner
    Link to this post
    Hey Mike,

    As a follow up to this thread. I have the same question for a SmartBusinessEntityAdApter.

    I have a form with 2 adapters. In this case ItemAdapter and HistoryTotsAdapter.

    My BE has relation defined between the Item table and HistoryTots (one to many).

    In my form constructor I am calling ItemAdapter:RetrieveData.

    For my HistoryTotsAdapter the DataSource is the ItemAdapter.

    All is good...I see all child records of the Item. I now want to limit the result set to not only the joined records of the ITem but records where the HistoryTots.Period = "M". I have set the HistoryTotsAdapter:QueryString = HistoryTots.Period = "M" AND

    This seems to give me the results I am looing for. Does this sound like the best way to handle this?
  5. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    Answered
    01 Dec 2018 in reply to Roger Blanchard
    Link to this post
    Hi Roger,

    that is a good approach.

    Depending on the UI situation subscribing tho the CollectFilterValues event of Item SmartBusinessEntityAdapter might be better. He're a sample that injects a filter on eSmartObjectInstance.PageGuid based on a selection in the UI.  
       /**
         * Purpose: Event handler for the CollectFilterValues event of the instancesAdapter
         * Notes:
         * @param sender The reference to the object that raised the event
         * @param e The CollectFilterValuesEventArgs with the data for this event
         */
        METHOD PRIVATE VOID instancesAdapter_CollectFilterValues (sender AS Progress.Lang.Object,
                                                                  e AS CollectFilterValuesEventArgs):

            IF cbPageGuid:SelectedIndex > 0 THEN
                e:QueryExpressions:GetItem ("eSmartObjectInstance":U):Add ("eSmartObjectInstance.PageGuid":U, OperatorEnum:EQ, UNBOX (cbPageGuid:Value)) .

            CATCH err AS Progress.Lang.Error:
                ErrorHelper:ShowErrorMessage (err) .
            END CATCH.

        END METHOD.
  6. Roger Blanchard
    Roger Blanchard avatar
    381 posts
    Registered:
    29 Jun 2018
    02 Dec 2018 in reply to Mike Fechner
    Link to this post
    thanks mike...I will check that out.
6 posts, 3 answered