web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

refreshQueryRun not working for SysLookupMultiSelectCtrl

(0) ShareShare
ReportReport
Posted on by

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

  • Martina Bergamo Profile Picture
    1,470 on at

    Hi! Have you found a solution for this?

    I've exactly the same problem...

  • Suggested answer
    reachnaidu Profile Picture
    890 on at

    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();

    }

  • Martina Bergamo Profile Picture
    1,470 on at

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

  • Suggested answer
    reachnaidu Profile Picture
    890 on at

    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
    890 on at

    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
    1,470 on at

    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!


  • reachnaidu Profile Picture
    890 on at

    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
    1,470 on at

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

    Thanks

  • Community Member Profile Picture
    on at

    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

  • reachnaidu Profile Picture
    890 on at

    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

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Prashant Singh Profile Picture

Prashant Singh 2

#1
nmaenpaa Profile Picture

nmaenpaa 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans