How To Get Selected Query Range Value

How to get selected query range value. The findQueryFilter method is used to find and retrieve a specific query filter criterion from a query. 

Scenario 

How to get selected query value from the below screenshot.  For example, I need the value given for the criteria of ‘Journal lines’ from the query. 

Selected Query Range Value

High level resolution steps 

  • Create an extension class for the form and write code in the init() method. 
  • Query: This is an instance of the Query class which represents the data query. 
  • QueryBuildDataSource (qbds): This represents a data source within the query to which you want to apply the filter. 
  • QueryFilter: This is an instance of the QueryFilter class that represents a filter criterion within the query. 
  • findQueryFilter(‘MyFilterName’): This method searches for a query filter with the specified name (‘MyFilterName’). If found, it returns the QueryFilter object; otherwise, it returns null. 
  • Using the query filter: Once you have obtained the QueryFilter object, you can apply it to a data range (using addRange) to restrict the data returned by the query. 

Detailed resolution steps 

Scenario 

Need to get the value of the query.


            ///  

/// COC for form LedgerTransVoucher 

///  

[ExtensionOf(formStr(LedgerTransVoucher))] 

internal final class SCCInforicaLedgerTransVoucher_Form_Extension 

{ 

    ///  

    /// Override the init() method 

    ///  

    public void init() 

    { 

        Query                   query; 

        QueryBuildDataSource    qbdsLedgerJournalTrans, qbdsLedgerJournalTrans1, qbdsCustInvoiceTable, qbdsCustInvoiceTable1; 

        QueryRun                queryRun; 

        QueryFilter             queryFilterLedgerJournal, queryFilterCustInvoice; 

 

        next init();   

 

        query = generalJournalEntry_ds.query(); 

 

        //Filter the LedgerJournalTrans 

 

        qbdsLedgerJournalTrans1     = query.dataSourceTable(tableNum(LedgerJournalTrans)); 

        queryFilterLedgerJournal    = query.findQueryFilter(qbdsLedgerJournalTrans1, fieldStr(LedgerJournalTrans,Invoice)); 

 

        if (queryFilterLedgerJournal != null && queryFilterLedgerJournal.value() == "") 

        { 

            qbdsLedgerJournalTrans = SysQuery::findOrCreateDataSource(query, tableNum(LedgerJournalTrans)); 

            qbdsLedgerJournalTrans.addRange(fieldNum(LedgerJournalTrans, Invoice)).value(SysQuery::valueNotEmptyString()); 

            qbdsLedgerJournalTrans.relations(true); 

            qbdsLedgerJournalTrans.joinMode(JoinMode::InnerJoin); 

 

            queryRun    = new QueryRun(query); 

            generalJournalEntry_ds.query(queryRun.query()); 

        }         

    } 

} 
    

Explanation 

  1. Query: This is an instance of the Query class which represents the data query. 
  1. QueryBuildDataSource (qbds): This represents a data source within the query to which you want to apply the filter. 
  1. QueryFilter: This is an instance of the QueryFilter class that represents a filter criterion within the query. 
  1. findQueryFilter(‘MyFilterName’): This method searches for a query filter with the specified name (‘MyFilterName’). If found, it returns the QueryFilter object; otherwise, it returns null. 
  1. Using the query filter: Once you have obtained the QueryFilter object, you can apply it to a data range (using addRange) to restrict the data returned by the query. 
  1. In the above example, getting the query and check what is the value of invoice in the datasource table ‘LedgerJournalTrans’.  I used ‘findQueryFilter’ method to get the value in ‘queryFilterLedgerJournal’.  
  1. If the value of ‘queryFilterLedgerJournal’ is not null, the statements inside the if loop will execute.  

Output 

When we run the above code, the query value is null.