Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / selectionChange() not ...
Finance forum
Answered

selectionChange() not working as expected

Posted on by 1,867
Dears,

I have a basic simplelist form with a query as its data source, which includes two data tables with a common relation. My goal is to filter the grid using the bound controller WeekDays. Initially, it filters the records as expected. However, when I reload the form for the second time and try to filter, it throws an error: /Cannot create a record in RouteData (RouteData). The record already exists.  I am puzzled as to why the selectionChange() function is not working as expected. Kindly review my code and provide insights.
 
Form Class  :
 
 QueryBuildRange qrWeek;
 RoutMaster routMaster;
 
Form init():
 
public void init()
{
    super();
    
 //   routMaster = element.args().record();
  //  Day.selection(WeekDays::Sunday);
 //   info(strFmt(/Day %1/,Day.valueStr()));
}
 
FormDataSource
 
public void executeQuery()
{
    QueryBuildDataSource  queryBuildDataSource;
            queryBuildDataSource = this.query().dataSourceTable(tablenum(RoutMaster));
            queryBuildDataSource.clearRanges();
            queryBuildDataSource.addRange(fieldnum(RoutMaster, WeekDays)).value(queryValue(RoutMaster_1_WeekDays.selection()));
          
         super();
 
  /*  qrWeek = SysQuery::findOrCreateRange(this.query().dataSourceTable(tableNum(RoutMaster)), fieldNum(RoutMaster, WeekDays));

    if(RoutMaster_1_WeekDays.selection())
    {
        qrWeek.value(int2str(RoutMaster_1_WeekDays.selection()));
    }
    else
     {
    qrWeek.value(SysQuery::valueUnlimited());
   }
     super();*/
}
 
Combo Box:
 
public int selectionChange()
{
    int ret;
    ret = super();
    RouteData_1_DS.executeQuery();
    return ret;
}
 
 
 
  • Verified answer
    Faqruddin Profile Picture
    Faqruddin 1,867 on at
    selectionChange() not working as expected
    Its unbound control. The issue has been solved recompile the project.
     
    Thank you.
  • Martin Dráb Profile Picture
    Martin Dráb 227,996 Super User 2024 Season 2 on at
    selectionChange() not working as expected
    First of all, let me make your code easier to read. I see that most of it is commented out and it can be simplified a bit.
     
    RoutMaster_1 data source:
    public void executeQuery()
    {
        QueryBuildDataSource qbds = this.queryBuildDataSource());
        qbds.clearRanges();
        qbds.addRange(fieldnum(RoutMaster, WeekDays)).value(queryValue(RoutMaster_1_WeekDays.selection()));
    
        super();
    }
    Combo Box:
    public int selectionChange()
    {
        int ret = super();
    
        RouteData_1_DS.executeQuery();
        
        return ret;
    }
    The error you mentioned is related to saving, not filtering. What is its stack trace?
     
    By the way, the name of RoutMaster_1_WeekDays control suggests that it's a control bound to WeekDays field of RoutMaster_1 data source. If it's unbound, as you mentioned, you should change the name to avoid confusion.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

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

Dynamics 365 Community Newsletter - August 2024

Catch up on the latest D365 Community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 227,996 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans