Step 1: Understand Query Factory
A query factory is a JavaScript function that generates custom query constraints for autocomplete suggestions. When a user types in a link column, the query factory dynamically builds a filter that restricts which items appear in the dropdown.window.risksheet.queryFactories object and referenced by name in column configuration.
Step 2: Register a Query Factory Function
Add your query factory function to the Risksheet configuration or a custom script. Query factories are registered as named functions:queryFactory property on a column references the registered factory name. When the user edits this column, the factory function is called to generate additional query constraints.
Step 3: Create a Dependent Column Filter
A common use case is filtering one upstream column based on the value selected in another. For example, filtering Requirements based on a linked System Element:- Define the first column (System Element) as a standard link column.
- Define the second column (Requirement) with a
queryFactorythat reads the selected System Element. - The factory returns a query that limits Requirements to those linked to the selected System Element.
Step 4: Configure canCreate for Link Columns
Control whether users can create new items directly from the link editor:canCreate to false allows selection and unlinking of existing items while disabling item creation from the autocomplete editor. The default value of canCreate is true.
Step 5: Use Query Factory with Multi-Item Links
Query factories also work withmultiItemLink columns. The behavior is the same — the factory function provides additional query constraints that filter the autocomplete results.
Step 6: Combine with Velocity Top Panel
For advanced scenarios, combine a Velocity script in the top panel template with a query factory to filter items based on document-level custom fields:- Use a Velocity script in
risksheetTopPanel.vmto extract document custom field values into JavaScript variables. - The query factory function reads these variables and constructs a Lucene query using the document field values.
Query factory function signatures and the exact
window.risksheet.queryFactories registration mechanism may vary by Risksheet version. Test your implementation in a development environment.Verification
- Open a Risksheet document with your query factory configured.
- Click on a cell in the column that uses the query factory.
- Type at least 3 characters to trigger autocomplete.
- Verify that only items matching your factory’s filter criteria appear in the dropdown.
See Also
- Configure Queries — static Lucene query configuration
- Enable Conditional Linking — alternative approach to link filtering
- Configure Upstream Traceability Columns — set up the link columns that use query factories
- Customize the Top Panel — Velocity templates for document-level data