Skip to main content

Notifications

Announcements

No record found.

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

selectionChange() not working as expected

(0) ShareShare
ReportReport
Posted on by 1,873
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,873 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 230,605 Most Valuable Professional 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.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,605 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans