Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Grid filter value based off previous form

Posted on by 65

Hello, so I have a grid on a form (VMDealerProductLine) that can be accessed by the same menu item but two different places. One being CustTableListPage, the other from the menus.

Based off a modification, we set an initial value to filter the grid in the init method of the data source CustTableCube. Currently, that filter is causing problems for users depending on which place they access the grid from(CustTableListPage or the menu).

My solution is to filter the route the system takes based off the access point used to access said form grid (VMDealerProductLine).

This is what I've done to do this:

public void init()
{
    QueryBuildDataSource qbds;
    
    super();

    gCallerForm     = element.args().caller();
    
    if (element.args().caller() && element.args().caller().name() == formStr(CustTableListPage))
    {
        super();
        qbds.addDataSource(TableNum(CustTableCube));
        qbds.addRange(fieldNum(CustTableCube, CustGroup));
        qbds.addLink(fieldNum(frFloorPlanAssignment, dealercustomer), fieldNum(CustTableCube, AccountNum));
        qbds.addRange(fieldNum(frFloorPlanAssignment, EndDate)).value('>' queryValue(today()-1));
    }
    
    else
    {
        super();
        qbds.addDataSource(TableNum(CustTableCube));
        qbds.addRange(fieldNum(CustTableCube, CustGroup)).value("Dealers");
        qbds.addLink(fieldNum(frFloorPlanAssignment, dealercustomer), fieldNum(CustTableCube, AccountNum));
        qbds.addRange(fieldNum(frFloorPlanAssignment, EndDate)).value('>' queryValue(today()-1));
    }

Before I began making modifications such as my variable declaration up top, super() was running first. That would take me to my method init on CustTableCube which was setting the filter value when accessing VMDealerProductLine.

public void init()
{
   /* QueryBuildDataSource qbds;

    super();

    qbds = this.queryBuildDataSource();

    qbds.addRange(fieldNum(CustTableCube, CustGroup)).value("Dealers");*/

}

It would then move on to another init method on data source frFloorPlanassignment.

public void init()
{/*
    super();

    this.queryBuildDataSource().addLink(fieldNum(frFloorPlanAssignment, dealercustomer), fieldNum(CustTableCube, AccountNum));

    this.queryBuildDataSource().addRange(fieldNum(frFloorPlanAssignment, EndDate)).value('>' queryValue(today()-1));*/
}

I tried setting up a parm method on the form which would hold the caller value and I can access that on the data source to tell super and CustTableCube which query build route to take.

It did not work because I'm guessing the variable was out of scope. 

I thought it might be possible to take all those query modifications from those table init methods and add them here THEN call super(). But I'm getting an error saying QueryBuildDatasourceObject not initialized.

I wanted to see if anyone had any suggestions on how to accomplish my original goal.

 

Also, if anyone has clarification on what exactly super is doing with all of this and what I can use it for myself. 

  • JGjinx321 Profile Picture
    JGjinx321 65 on at
    RE: Grid filter value based off previous form

    Thank you!

  • Verified answer
    GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: Grid filter value based off previous form

    So you have two tables in the form - CustTableCube and frFloorPlanAssignment tables..

    So now add the code in the executeQuery method of CustTableCube to add customer group.

    this.queryBuildDataSource().addRange(fieldNum(CustTableCube, CustGroup)).value(queryvalue('Dealer'));

    Then end date range in the executeQuery method of frFloorPlanAssignment.

    this.queryBuildDataSource().addRange(fieldNum(frFloorPlanAssignment, EndDate)).value('>' queryValue(today()-1));
    

    Remove the form init method and datasource init method logic.

    Thanks,

    Girish S.

  • JGjinx321 Profile Picture
    JGjinx321 65 on at
    RE: Grid filter value based off previous form

    It is on the CustTableCube table.

    To clarify I have two data sources being CustTableCube, and frFloorPlanAssignment tables.

    VMDealerProductLine is the form.

    there is a VMDealerProductLine table which seems to be the join source for a lot of the tables but as far as I know VMDealerProductLine table doesn't have much to do with my current situation.

    Besides the executeQuery method you had suggested.

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: Grid filter value based off previous form

    Do you have custGroup field on the "VMDealerProductLine " or "frFloorPlanAssignment" table?

    Thanks,

    Girish S.

  • JGjinx321 Profile Picture
    JGjinx321 65 on at
    RE: Grid filter value based off previous form

    It's simply the CustGroup field with a value of "Dealers" for it.

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: Grid filter value based off previous form

    I want to know the fields that need to be added as filter to the form datasource. Based on that I will give you the suggestions

    Thanks,

    Girish S.

  • JGjinx321 Profile Picture
    JGjinx321 65 on at
    RE: Grid filter value based off previous form

    Thank you for your help Girish! Quick question, if I make my variable (gCallerForm) global would I still need to move the query methods from their tables (frFloorPlanAssignment) and (CustTableCube) to the execute query method on VMDealerProductLine? Since It's global I should be able to access it whether I'm currently in a data source's method or the form's method right?

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: Grid filter value based off previous form

    Also you have customer account number field in frFloorPlanAssignment. So get the caller record using.

    custtable cust;
    // this code should be init method.
    cut = element.args().record();
    //this code should be in datasource execute query method.
    this.queryBuildDataSource().addRange(fieldNum(frFloorPlanAssignment, EndDate)).value('>' queryValue(today()-1));
    this.queryBuildDataSource().addRange(fieldNum(frFloorPlanAssignment, dealercustomer)).value(queryvalue(cust.AccountNUm));
     

    Thanks,

    Girish S.

  • GirishS Profile Picture
    GirishS 27,832 Super User 2024 Season 1 on at
    RE: Grid filter value based off previous form

    Hi JGjinx321,

    Can you tell me the field ranges that you need to be added in the form datasource?

    Instead of form init method and datasource init method - Add you code in "VMDealerProductLine " datasource "executeQuery" method.

    this.queryBuildDataSource().addRange(fieldNum(frFloorPlanAssignment, EndDate)).value('>' queryValue(today()-1));

    Adding the code in the above said method is enough for your scenario.

    So try to get the caller form in the init method and buffer for caller form must be declared as global.

    Thanks,

    Girish S.

  • JGjinx321 Profile Picture
    JGjinx321 65 on at
    RE: Grid filter value based off previous form

    Yes Girish, that is the case.

    I tried adding the filter on the form data source but it seems I lost my filter variable by the time I reached the data source.

    I then tried to move the querybuilddatasource methods away from the tables and keeping them on the Form init method but I get the error:

    "QueryBuildDataSource Object not initialized".

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans