Hide 2 rows from ax on open of the form

Hi,

I wanted to hide two rows from a grid as shown below

If CaeIdentificationType is insurance card and labour card,it should hide completely the 2 rows

pastedimage1538286399902v1.png

Thanks

Use query ranges to filter out data. For example, you can use code like this in datasource’s init():

FieldId idTypeFieldId = fieldNum(MyTable, IdentificationType);

this.queryBuildRange().addRange(idTypeFieldId).value(SysQuery::valueNot(MyIdentificationType::InsuranceCard));
this.queryBuildRange().addRange(idTypeFieldId).value(SysQuery::valueNot(MyIdentificationType::LaborCard));

Of course, you tell us little about your form, therefore I had to make up a few things. You’ll have to adjust the solution to match your situation.

Thanks MArtin. I wrote the below but it’s not working

public void init()
{
    QueryBuildDataSource queryBuildRange;
    super();
    this.query().dataSourceNo(1).addSortField(fieldNum(CaeIdentification,CaeIdentificationType ), SortOrder::Ascending);
    //FieldId idTypeFieldId = fieldNum(CaeIdentification, IdentificationType);

    this.queryBuildDataSource().addRange(fieldNum(CaeIdentification, CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::InsuranceCard));
this.queryBuildDataSource().addRange(fieldNum(CaeIdentification, CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::LabourCard));
}

Thanks

Sorry, I can’t give you any advice about “it’s not working”. I would need a least some information about your problem.

I meant that i did not get any error message or anything. But the rows were not hidden. Still the rows are showing .

I am not sure whether the above code is correct or not.

The grid still shows with the rows insurance card and labor card. But i wanted the rows to not been shown.

I have written the following code. Now the labor card disappears …but when i add another code for insurance card then both appears again

public void init()
{
    QueryBuildDataSource queryBuildRange;
    super();
    this.query().dataSourceNo(1).addSortField(fieldNum(CaeIdentification,CaeIdentificationType ), SortOrder::Ascending);
    //FieldId idTypeFieldId = fieldNum(CaeIdentification, IdentificationType);

   // this.queryBuildDataSource().addRange(fieldNum(CaeIdentification, CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::InsuranceCard));
//this.queryBuildDataSource().addRange(fieldNum(CaeIdentification, CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::LabourCard));
   queryBuildRange = this.query().dataSourceTable(tableNum( CaeIdentification));
    queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::LabourCard));
   // queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::InsuranceCard));
}

When a query doesn’t behave as expected, you should debug it. Just looking at whether the form shows data or not doesn’t tell you anything about what’s wrong with your query, so it’s clearly not a sufficient way of debugging.

What I recommend as the first step is checking what you get from toString() method of the QueryBuildDataSource object. This will show pseudo-SQL code that you’ve generated by QueryBuild* objects.
The difference between your and my code is that you use this.query().dataSourceTable(tableNum(CaeIdentification)) instead of this.queryBuildDataSource(), but it would return the same thing if you used it in the init() method of the right datasource. It seems that you put your code somewhere else. Debugging your query (as discussed above) would reveal if you applied ranges to a wrong datasource.

Regarding your problem with “another code”, I obviously can’t help you unless you tell me at least something about it.

yes i debugged. My code is working partially but what happens is first time it runs the below query:

queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::LabourCard));

and makes the LabourCard row to disappear which is the expected output

then it rums the below query

queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot(CaeIdentificationType::InsuranceCard));

and makes Labourcard row to appear again and insurance card row to disappear.

The above code doesn’t do both rows to disappear. Instead it remains one row and other row to disappear.

Thanks

The line of code is fine, the problem will be in where and when you use it. Please share this information with us.

I have used it in the Form level data source table init method. When the form opens ,it still makes labourcard field and insurance field to appear.

public void init()
{
    QueryBuildDataSource queryBuildRange;
    super();
    this.query().dataSourceNo(1).addSortField(fieldNum(CaeIdentification,CaeIdentificationType ), SortOrder::Ascending);

    queryBuildRange = this.query().dataSourceTable(tableNum( CaeIdentification));
    queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot
    (CaeIdentificationType::LabourCard ));
     queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot
    (CaeIdentificationType::InsuranceCard ));

}

You really should look at the query you’ve generated, instead of just looking at the data it returns. You can see that you’re unable to solve your problem without that, therefore what you’re doing clearly isn’t sufficient for you.

If you check the query, I think you’ll find that the query has a condition to returns everything that isn’t LabourCard or it isn’t InsuranceCard, which means that it returns everything (if it’s LabourCard, it passes the test of not being InsuranceCard and vice versa). Sorry, I didn’t realize that when giving you my first reply.

You have two options. You can either reverse the condition and enumerate all allowed values:

addRange(idTypeFieldId).value(queryValue(CaeIdentificationType::Visa));
addRange(idTypeFieldId).value(queryValue(CaeIdentificationType::Uid));
...

Or you’ll have to use expressions in query ranges to use the && operator instead of ||.

Thanks for the suggestion. First option was behaving the same way and the second option code i wrote as below

    queryBuildRange.addRange(fieldNum(CaeIdentification,CaeIdentificationType)).value(SysQuery::valueNot(
    (CaeIdentificationType::LabourCard ) && (CaeIdentificationType::InsuranceCard)));

i am not sure whether the above query is wrong which i have written but it was displaying all the rows.

Thanks

Your code is completely wrong. I suggest you stick to the first option, it’s much easier to develop and maintain. Please show me your code; I can’t find your bug if you don’t tell me what you did.

If you insist in using the extended query syntax, please read the documentation to understand how it should be done.

Also, I still think that you should learn how the debug queries. You just try something and see that it doens’t work, but you have no idea why.

Ok thanks for your response. I will try to debug and find out the solution