Retrieving Rows from a Data Source
The GetDataSourceRow function can be used to search a data source for rows that match a specific filter. If one or more matches are found, values in the first matching row will be passed to the data source's aliases. Depending on how the function is written, the value it returns will be one of the following:
- The number of rows that match the specified filter.
- True or False, indicating whether the function was able to find at least one matching row.
The function's syntax is as follows:
GetDataSourceRow( DataSource, FilterName, ReturnResultCount, Refresh );
The ReturnResultCount and Refresh parameters are optional.
DataSource is a string containing the name of the data source you want to search.
FilterName is a string containing the name of a filter associated with the selected data source. Only rows matching this filter will be returned by the function.
ReturnResultCount is a Boolean that determines the value returned by the function. If it is set to True, the function will return the number of rows in your data source that satisfy the specified filter; otherwise, the function will return True or False depending on whether at least one matching row could be found.
Refresh is a Boolean value that determines whether the function will first refresh the data source before executing.
You can use the function's syntax to write the expression manually but there is also the option of using the Data Source Expression wizard to quickly generate the GetDataSourceRow expression.
Before implementing either of these options make sure you have created a writeable data source with at least one Filter, so the expression can retrieve one or more rows of data that satisfies a specific filter, then assign the values in that row to the selected data source's aliases.
Use the implementation steps below to automatically generate the GetDataSourceRow function.
Implementation:
- Open the Expression Editor.
- If the expression already has some content, place the keyboard cursor where you want the new statement to appear.
- Right-click anywhere in the main Expression panel.
- Select Create Data Source Expression.
- Use the Data Source drop-down menu to select the data source you want to query.
- Select the Get an Entry from Your Data Source radio button.
- (Optional) If you want the GetDataSourceRow statement to return the number of rows that match your filter, tick the Return Row Count check box. If you leave the check box unticked, the statement will return True if any rows are found, and False otherwise.
- Click Next.
- Use the Filter Parameter drop-down menu to specify the filter you want to use to identify data for retrieval.
- Click Finish.
- Save the expression before closing the expression editor.