I want to automatically apply a foundset filter whenever a form is used so that only a subset of the records are displayed, to achieve this I have written the following code:
- Code: Select all
var filterName = controller.getName();
var params = foundset.getFoundSetFilterParams(filterName);
if (params.length == 0) {
//apply filter so only issues display
/** @type {QBSelect<db:/dbname/case_actions>} */
var query = datasources.db.dbname.case_actions.createSelect();
//Filter on case action type for only stage 1,2,3 issues
/** @type {Array<String>} */
var caseActionTypeId = [];
caseActionTypeId.push(scopes.caseActions.stage1IssueTypeId);
caseActionTypeId.push(scopes.caseActions.stage2IssueTypeId);
caseActionTypeId.push(scopes.caseActions.stage3IssueTypeId);
query.where.add(query.columns.case_action_type_id.isin(caseActionTypeId));
foundset.addFoundSetFilterParam(query, filterName);
}
The problem I having is I cannot find the right place to apply this filter because the form is being loaded on to a tab using a relation. I have used the debugger to see what is happening in each of the following:
- In the onLoad event of the form
The method is called when the form is loaded and the filter is added to the foundset. Unfortunately the records are not filtered and I get all the records in the relation
- In the onShow event of the form
The method is called when the form is loaded and the filter is added to the foundset. When the form is first shown the records are not filtered but if I hide the form and reshow it then they do get filtered (we are making progress!)
- In the onRecordSelection event of the form
The method is called when the form is loaded and the filter is added to the foundset. The records are all filtered and everything is as I want it to be BUT this is very inefficient as I am calling the method every time a record is selected and performing an unnecessary check
TIA
Steve