how to filter grid using another string control in the form in D365 ax

Hi,

 how to filter grid using another string control in the form in D365 ax


Add control in the form and make Auto Declaration = YES

Go to Control --> Methods --> OverWrite below methods for lookup and filter Grid in the form

  [Control("String")]

    class FormStringContainerNo

    {

        /// <summary>

        ///

        /// </summary>

        public void lookup()

        {

           // super();


           SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(StagingTable), this);

            Query q = new Query();

            QueryBuildDataSource qbds;

           

            sysTableLookup.addLookupfield(fieldNum(StagingTable, ConNo), true);

            qbds = q.addDataSource(tableNum(StagingTable));

           

            sysTableLookup.parmQuery(q);

            sysTableLookup.performFormLookup();

        }


        /// <summary>

        ///

        /// </summary>

        /// <returns></returns>

        public boolean modified()

        {

            boolean ret;

        

            ret = super();


        

            if(FormStringContainerNo.text() != '') //Check the combo box has value or not

            {

                SysQuery::findOrCreateRange( StagingTable_ds.query().dataSourceTable( tableNum( StagingTable )),

fieldNum( StagingTable, ConNo ) ).value( SysQuery::value( FormStringContainerNo.text() ) );

            }

            else

            {

                SysQuery::findOrCreateRange( StagingTable_ds.query().dataSourceTable( tableNum( StagingTable )),

fieldNum( StagingTable, ContNo ) ).value( SysQuery::valueUnlimited() );

            }

        

StagingTable_ds.executeQuery();


            return ret;

        }


    }

http://dynamicsaxhari.blogspot.com/2014/12/filtering-records_15.html

you can do it much simplier with findOrCreateRange

if(ExamResultCombo.valueStr() != '') //Check the combo box has value or not
{
SysQuery::findOrCreateRange( Hari_ExamResult_ds.query().dataSourceTable( tableNum( Hari_ExamResult )),
fieldNum( Hari_ExamResult, ExamResult ) ).value( SysQuery::value( ExamResultCombo.valueStr() ) );
}
else
{
SysQuery::findOrCreateRange( Hari_ExamResult_ds.query().dataSourceTable( tableNum( Hari_ExamResult )),
fieldNum( Hari_ExamResult, ExamResult ) ).value( SysQuery::valueUnlimited() );
}

do not forget to clear range when ExamResultCombo.valueStr() or your grid will be stay with records when you clear your combo!





Comments

Post a Comment