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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

selectionChange() not working as expected

(0) ShareShare
ReportReport
Posted on by 1,909
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;
}
 
 
 
I have the same question (0)
  • Martin Dráb Profile Picture
    240,075 Most Valuable Professional on at
    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.
  • Verified answer
    Faqruddin Profile Picture
    1,909 on at
    Its unbound control. The issue has been solved recompile the project.
     
    Thank you.

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

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 393 Super User 2026 Season 1

#2
Subra Profile Picture

Subra 385

#3
Martin Dráb Profile Picture

Martin Dráb 252 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans