SysQuery is a helper class provided by Microsoft for working with queries dynamically. It has all its methods set as ‘static.’ It provides numerous functionalities that allow one to add data source in a query, add range, apply sort, etc. in a user-friendly system. This article will provide demonstrations for the most commonly used methods from SysQuery:
findOrCreateDataSource()
FindOrCreate is mainly used to check whether or not the query already contains the data source. If it does not, a data source will be created. FindOrCreate is most efficient when an event developer must write a code in which the event must be fired multiple times. This function allows developers to prevent adding additional elements to data sources. This is the most common situation in which findOrCreateDatasource() is used to avoid multiple addition of data sources in a query.
Because this method is static, it uses Query as the first parameter. The next parameter will be the table id of the table that is being used as the data source in the query. Below is the method signature:
public static QueryBuildDataSource findOrCreateDataSource(Query _query, tableId _tableId, tableId _parentTableId = 0)
An alternative option, findOrCreateDataSourceByName() works in a similar fashion, but uses the table name for table identification in parameters.
findOrCreateRange()
This method is used to check whether or not a range already exists. If the range exists, the object will either be returned or a range according to the provided parameter will be created and returned. Using the findOrCreateRange() method, allows developers to avoid the possibility of adding a single range multiple times. The below is an example of the method:
range = SysQuery::findOrCreateRange(query.dataSourceName("CustTable"), fieldNum(CustTable, AccountNum));
range.value(SysQuery::value("123"));
There are other methods for specifying value for conditions in a range below:
SysQuery::range()
Range() method is used to specify value ranges of any type. This is most commonly used for specifying date ranges.
Comments
Post a Comment