Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

refreshQueryRun not working for SysLookupMultiSelectCtrl

Posted on by Microsoft Employee

I have two multiselect fields in a form. I want to populate second field based on the selected value of first field. In form init method, I have initialized the mutiselect fields. And On modified method of first field I am calling msCtrlDealerGroup.refreshQueryRun(element.dealerGroupQuery()); but its not refershing the grid. 

Note: I am following the last post in the thread of this blog: http://dynamicsuser.net/forums/p/79568/441037.aspx 

Anyone please help.

Thanks,

Samiya

*This post is locked for comments

  • VasanthArivali Profile Picture
    VasanthArivali 1,600 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    Hi Potturi,

    Thanks for your post, It works for me :-)

    // Vasanth Arivali

  • reachnaidu Profile Picture
    reachnaidu 890 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    ok i got it. That suprises me as well. If we create a new new Query Run and apply ranges the control is not getting filtered but we get the query from old QueryRun Object and apply ranges then  refresh works .. Interesting. Thanks

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    Hi,

    Try this code in form init method.

       Query QueryRevenue, QueryRevenueSub;  

       QueryBuildRange qbrQueryRevenue, qbrQueryTagCategroy;

       QueryBuildDataSource qbdFinancialTag, qbdFinancialTagSub;

       DimensionAttribute  DimAttrRevenue, DimAttrSubRev;

       DimensionAttributeDirCategory DimAttrDirRevenue, DimAttrDirRevenueSub;

       DimensionAttribute dimensionRevenue, dimensionRevenuesub;

       QueryRevenue = new Query();

       // filtered Revenue related dimension values

       select * from dimensionRevenue where dimensionRevenue.Name == CustParameters::find().RevenueGroup;

       select RecId from DimAttrRevenue where DimAttrRevenue.Name == dimensionRevenue.Name;

       select DirCategory from DimAttrDirRevenue where DimAttrDirRevenue.DimensionAttribute == DimAttrRevenue.RecId;

       qbdFinancialTag = QueryRevenue.addDataSource(TableNum(DimensionFinancialTag));

       qbrQueryRevenue = qbdFinancialTag.addRange(FieldNum(DimensionFinancialTag, FinancialTagCategory));

       qbrQueryRevenue.value(strFmt('%1',DimAttrDirRevenue.DirCategory));

       qbdFinancialTag.fields().addField(fieldNum(DimensionFinancialTag,Value));

       qbdFinancialTag.fields().addField(fieldNum(DimensionFinancialTag,Description));

       super();

       MultiselectRevenue = sysLookupMultiselectCtrl::constructWithQuery(element,RevenueGroup,QueryRevenue );

    Regards,

    Edwin

  • Martina Bergamo Profile Picture
    Martina Bergamo 1,470 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    Ok it works. My problem was the new initialization of the queryRun!

    Thanks

  • reachnaidu Profile Picture
    reachnaidu 890 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    Were you able to refresh the second multi select field based on the selection from the first multi Select ? The RefreshQueryRun needs the same Old QueryRun that was used during initialization of the control. If we update the range of the QueryRun Query (as i mentioned above)  and pass the QueryRun to the RefreshQueryRun , it works.

    Why are we again doing a look up externally ?

  • Martina Bergamo Profile Picture
    Martina Bergamo 1,470 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    The problem is (as described in the title) that the "refreshQueryRun" does not work.

    I've seen that the refreshQueryRun refresh only the queryRun and not the query, that is used in the method ctrlNames_lookup (of the class

    SysLookupMultiSelectGrid):

    SysLookupMultiSelectGrid::lookup(query, fsCtrlIds, fsCtrlNamesTmp, selectField, queryRun);
    

    At this point, the queryRun has the new value, but the query, has the old value! And the queryRun is not used anymore in the code!


  • Suggested answer
    reachnaidu Profile Picture
    reachnaidu 890 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    Hi,

        Please follow these steps to fix the problem if you had not already fixed this. The multi select drop down selection should filter the second multi select drop down.

    i took an example of inventsite  and inventlocation as example

    In the class declaration of the form ,  have the necessary declarations for multiselectCtrl along with the QueryRun objects

    public class FormRun extends ObjectRun

    {

      SysLookupMultiSelectCtrl siteCtrl,locationCtrl;

       QueryRun locationQueryRun;

      Query q;

      QueryBuildDataSource qbd;

    }

    // In the init function of the form instantiate the two controls respectively. the

    msCtrlLocation , SiteCtrl are the two StringEdit Controls on the form with autoDeclaration to Yes

      q = new Query();

      qbd = q.addDataSource(TableNum(InventLocation));

      qbd.addRange(FieldNum(InventLocation, InventSiteId));

      locationQueryRun = new QueryRun(q);

      super();

      locationCtrl   = SysLookupMultiSelectCtrl::constructWithQueryRun(element, msCtrlLocation, locationQueryRun);

      siteCtrl = SysLookupMultiSelectCtrl::construct(element, SiteCtrl, queryStr(InventSiteQry));

    In the modified function of Site Control which is siteCtrl

      boolean ret;

      int i;

      str siteID;

      ret = super();

    // Assign the selected site values into string siteid (which is a comma seperated site ids..)

      if (ret)

      {

         // siteContainer = ; // get actual value of the selected rows

          siteID = con2Str(siteCtrl.getSelectedFieldValues());

      }

    // Get the Query from the same QueryRun that was used in the init function on the form, if we use a seperate one it wont work.

    In our case it is locationQueryRun

    q = locationQueryRun.query() ;

     qbd = q.dataSourceTable(tableNum(InventLocation));

      qbd.clearRange(fieldNum(InventLocation, InventSiteId));

    // Pass the comma Seperated SiteID to addRange

      qbd.addRange(fieldNum(InventLocation, InventSiteId)).value(siteID);

    // RefreshQueryRun with the modified QueryRun

      locationCtrl.refreshQueryRun(locationQueryRun);

    The second multi Select list will be filtered based on the selection

    Hope this helps

    Thanks

  • Suggested answer
    reachnaidu Profile Picture
    reachnaidu 890 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    Hi,

         Please follow these steps to fix the problem if you had not already fixed this. The multi select drop down selection should filter the second multi select drop down.

    i took an example of inventsite  and inventlocation as example

    In the class declaration of the form ,  have the necessary declarations for multiselectCtrl along with the QueryRun objects

    public class FormRun extends ObjectRun

    {

       SysLookupMultiSelectCtrl siteCtrl,locationCtrl;

        QueryRun locationQueryRun;

       Query q;

       QueryBuildDataSource qbd;

    }

    // In the init function of the form instantiate the two controls respectively. the

    msCtrlLocation , SiteCtrl are the two StringEdit Controls on the form with autoDeclaration to Yes

       q = new Query();

       qbd = q.addDataSource(TableNum(InventLocation));

       qbd.addRange(FieldNum(InventLocation, InventSiteId));

       locationQueryRun = new QueryRun(q);

       super();

       locationCtrl   = SysLookupMultiSelectCtrl::constructWithQueryRun(element, msCtrlLocation, locationQueryRun);

       siteCtrl = SysLookupMultiSelectCtrl::construct(element, SiteCtrl, queryStr(InventSiteQry));

    In the modified function of Site Control which is siteCtrl

       boolean ret;

       int i;

       str siteID;

       ret = super();

    // Assign the selected site values into string siteid (which is a comma seperated site ids..)

       if (ret)

       {

          // siteContainer = ; // get actual value of the selected rows

           siteID = con2Str(siteCtrl.getSelectedFieldValues());

       }

    // Get the Query from the same QueryRun that was used in the init function on the form, if we use a seperate one it wont work.

    In our case it is locationQueryRun

    q = locationQueryRun.query() ;

      qbd = q.dataSourceTable(tableNum(InventLocation));

       qbd.clearRange(fieldNum(InventLocation, InventSiteId));

    // Pass the comma Seperated SiteID to addRange

       qbd.addRange(fieldNum(InventLocation, InventSiteId)).value(siteID);

    // RefreshQueryRun with the modified QueryRun

       locationCtrl.refreshQueryRun(locationQueryRun);

    The second multi Select list will be filtered based on the selection

    Hope this helps

    Thanks

  • Martina Bergamo Profile Picture
    Martina Bergamo 1,470 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    The problem is that the refreshQueryRun is called on the SysLookupMultiSelectCtrl and not on the SysTableLookup.

  • Suggested answer
    reachnaidu Profile Picture
    reachnaidu 890 on at
    RE: refreshQueryRun not working for SysLookupMultiSelectCtrl

    try overriding the lookup field on the second dropdown and pass the first field value as a range

    public void lookup(FormControl _formControl, str _filterStr)

    {

       Query                   query = new Query();

       SysTableLookup          sysTableLookup;

       QueryBuildDataSource    queryBuildDataSource;

       ;

       sysTableLookup = SysTableLookup::newParameters(tablenum(tblName), _formControl);

       sysTableLookup.addLookupfield(fieldnum(fieldid1, fieldid2)) ;

       queryBuildDataSource = query.addDataSource(tablenum(tblName));

       queryBuildDataSource.addRange(fieldNum(tblName,filterParentFieldId).value(ParentTable.FieldID);

       sysTableLookup.parmQuery(query);

       sysTableLookup.performFormLookup();

    }

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,900 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,297 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans