How to filter the form based on checkbox?

Hi,

I’ve added a checkbox in BOMVersion form and when it is checked form should show only records less than today’s date and active records

How can i add my query?

Thanks,

What do you mean by less than today’s date?

In BOMVersion form we’e Todate field so that field value’s should be less than today’s date one need to show when it is checked

Like this when i checked the box it should show the highlighted record

I’m trying to add coding in modified method of checkbox like this:

public boolean modified()
{
    boolean ret;

    ret = super();
    if(ret)
    {
         BOMVersion_ds.query().dataSourceTable(tablenum(BOMVersion)).addRange(fieldnum(BOMVersion,Active)).value(queryvalue(noyes::Yes));
         BOMVersion_ds.query().dataSourceTable(tablenum(BOMVersion)).addRange(fieldnum(BOMVersion,ToDate)).value(SysQuery::range('<systemdateget()', datenull()));
    }
    return ret;
}

But its not fitering the records

You can apply range on those fields (Active and todate) and set the value in the execute query.

Date currentDate = systemDateGet();

addRange(fieldNum(BOMVersion, ToDate)).value(strFmt(’(%1 < %2)’, fieldStr(BOMVersion, ToDate),
date2StrXpp(currentDate)));

If the check mark is not selected then use SysQuery::valueUnlimited()

The above is only example code.

Shall I do in modified or clicked method?

Use modified and call executeQuery in that method

public boolean modified()
{
    boolean ret;

    ret = super();
    if(ret)
    {
        
        qbr= BOMVersion_ds.query().dataSourceTable(tablenum(BOMVersion)).addRange(fieldnum(BOMVersion,ToDate));
        qbr= BOMVersion_ds.query().dataSourceTable(tableNum(BOMVersion)).addRange(fieldnum(BOMVersion,Active));
        BOMVersion_ds.executeQuery();
    }
    
    return ret;
}

This is my modified method and how should i pass value executequery method kranthi

You need to be adding ranges in init method of the form data source and setting the values to the ranges in executeQuery method of the form data source.

If you need an example, have a look at

\Forms\InventQuarantineOrder\Data Sources\InventQuarantineOrder\Methods\executeQuery

\Forms\InventQuarantineOrder\Data Sources\InventQuarantineOrder\Methods\init

How should i give condition if the checkbox is selected, kranthi?

if (checkBox.value())

I followed like inventquarantineorder form, here its my code

public class FormRun extends ObjectRun
{
    NoYes               showexpired;
    QueryBuildRange    qbr;
}

//BP Deviation documented
edit NoYes showexpired(boolean set, NoYes _showexpired)
{
    if (set)
    {
        showexpired = _showexpired;
        BOMVersion_ds.executeQuery();
    }
    return showexpired;
}

public void init()
{
    super();
    qbr=this.query().dataSourceTable(tablenum(BOMVersion)).addRange(fieldnum(BOMVersion,ToDate));
    //qbr=this.query().dataSourceTable(tablenum(BOMVersion)).addRange(fieldnum(BOMVersion,Active));
}


public void executeQuery()
{
    Date currentDate = systemDateGet();
    
    ;
    if(showexpired)
    {
       // qbr.value(strFmt('(%1 < %2)', fieldStr(BOMVersion, ToDate),date2StrXpp(currentDate)));
        qbr.value(strfmt('%1', queryValue(noyes::Yes)));
    }
    else
    {
        qbr.value(SysQuery::valueUnlimited());
    }
}

but its not filtering

You are setting the range on Todate field and passing the value as Yes. Shouldn’t you be setting the range on Active field?

sry i changed tat still its not filtering

Did you set the datamethod property on that check box control to the edit method you are using (showexpired)?

yes i did

You are also not calling the super() on executeQuery method.