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 :
Finance | Project Operations, Human Resources, ...
Answered

How to have a check box and interacted with grid

(0) ShareShare
ReportReport
Posted on by 309

Hello guys,

In my custom form with a grid, I want to add a check box, and this check box when it is "checked" it will only show rows with status "Posted", Default will be not checked, so it is showing all statuses. How am I gong to achieve this ?

I have added the check box in my form, and then in code editor, for the Click method, I tried to write code, something like this : 

[Control("CheckBox")]
class ShowPosted
{
    public void clicked()
        {
            QueryBuildDataSource        rangeDataSource;
            QueryBuildRange             criteriaShowPosted;
            /// 
            /// Execute and manage the filter pane and quick filter control queries.
            /// 
            Query initialQuery = new Query(My_Table_ds.query());
            rangeDataSource = initialQuery.dataSourceNo(1);

            if (this.checked())
            {
                criteriaShowPosted = SysQuery::findOrCreateRange(rangeDataSource, fieldnum(My_Table, Status));
                criteriaShowPosted.value(queryValue(My_Status::Posted));
            }
            My_Table_ds.executeQuery();
        }
}

Did I missed something ? or it is just not the way to do it ?

Thanks

I have the same question (0)
  • GirishS Profile Picture
    27,843 Moderator on at

    Hi Alex,

    Normally the filtering grid based on the condition will be added in the datasource execute query method.

    So based on the status field add range to the datasource execute query method.

    On the modified method of the check box control call datasource_ds.executeQuery() to filter the records.

    Thanks,

    Girish S.

  • Axel Cage Profile Picture
    309 on at

    Hi Girish,

    I tried to move all that in Clicked() to Modified(), but looks not working. It's like this : 

    [Control("CheckBox")]
        class ShowPosted
        {
            /// 
            /// Updates the form data selection criteria when the check box is clicked.
            /// 
            public void clicked()
            {
                super();
            }
    
            /// 
            ///
            /// 
            /// 
            public boolean modified()
            {
                QueryBuildDataSource        rangeDataSource;
                QueryBuildRange             criteriaShowPosted;
                /// 
                /// Execute and manage the filter pane and quick filter control queries.
                /// 
                Query initialQuery = new Query(My_Table_ds.query());
                rangeDataSource = initialQuery.dataSourceNo(1);
    
                if (this.checked())
                {
                    criteriaShowPosted = SysQuery::findOrCreateRange(rangeDataSource, fieldnum(My_Table, Status));
                    criteriaShowPosted.value(queryValue(My_Status::Posted));
                }
                
                My_Table_ds.executeQuery();
    
                return true;
            }
    
        }

    Thanks,

  • Verified answer
    GirishS Profile Picture
    27,843 Moderator on at

    Hi Alex,

    Refer to the below code.

    1. On the Form datasource - Methods - Override methods - Select execute query method and add the below code. Also set the "Auto Declaration" property of the check box control to yes.
      Public void executeQuery()
      {
          if(controlName.checked())
          {
              YourDataSourceName_ds.queryBuildDataSource().addRange(fieldnum(My_Table, Status)).value(queryvalue((My_Status::Posted)));
              
          }
          else
          {
              YourDataSourceName_ds.queryBuildDataSource().clearRanges();
          }
          YourDataSourceName_ds.refresh();
          super();
      }
    2. Now override the modified method of the control and add the below code. Expand the control >> Right click the methods and select modified.

    /// 
            ///
            /// 
            /// 
            public boolean modified()
            {
                boolean ret;
                ret = super();
                if(ret)
                {
                    YourDataSourceName_ds.executeQuery();
                    
                }
            }

    Thanks,

    Girish S.

  • Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at

    As you see, just saying that it's not working doesn't help you to fix the problem. You need to do more work on understand why it doesn't work. First of all, observe the behavior - it might already point to a specific problem. Then use the debugger - it's the most powerful tool you to find out what's going on in your code. And when you're writing code to modify form's query and the form doesn't behave as expected, a logic step is checking what query you've actually generated.

    The bug in your modified() method is that you don't modify the query used be the form. You create a new copy of the query and add a range there. It doesn't have any impact on the form and initialQuery gets destroyed at the end of modified().

    Therefore your code in modified() should look like thiis:

    public boolean modified()
    {
    	boolean ret = super();
    
    	QueryBuildDataSource myTableQbds = my_Table_ds.queryBuildDataSource();
    
    	if (this.checked())
    	{
    		QueryBuildRange criteriaShowPosted = SysQuery::findOrCreateRange(myTableQbds, fieldnum(My_Table, Status));
    		criteriaShowPosted.value(queryValue(My_Status::Posted));
    	}
    	
    	my_Table_ds.executeQuery();
    
    	return ret;
    }

  • Axel Cage Profile Picture
    309 on at

    Thank you very much for your guidance.

    It works!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans