Field Filtering
You can filter selection fields. In the underlying datastore, you can use any field to filter against.
As an example, build a datastore called 'Filtering Examples', and a vield 'Value' and a second field called 'Filter'. We will share some examples as how to filter.
Add some cities as values, and their country in the Filter field:
Bruges - Belgium
Brussels - Belgium
Ghent - Belgium
Amsterdam - The Netherlands
Rotterdam - The Netherlands
Frankfurt - Germany
Dresden - Germany
When entering a filter, select as type 'Plain text'. NCALC and Javascript will only be used in exceptional cases, you can already do a lot with the plain text filters.
To only show the cities from Belgium, use this filter:
[{ "fieldname": 'Filter', "filtervalue": 'Belgium' }]
To show the cities form both Germany & Belgium, use this filter:
[{ "fieldname": 'Filter', "filtervalue": 'Belgium' },{"connector": 'or', "fieldname": 'Filter', "filtervalue": 'Germany' }]
Create a text field, called 'Country'. If you want to filter against that text field:
[{ "fieldname": 'Filter', "filtervalue": #REPLACE-PARTVALUE-Country||# }]
Final note: Filters are applied to existing services, so a task runs every 5 minutes to apply any changes. You can kickstart this task by opening this link:
Best Practise with versions
When a template is exported from one installation and then imported in another, you might want to use different values in a select field. To avoid making a new datastore parameter to support this, you can also use filtering. This is how to set it up, do this from the start, to avoid issues when migrating:
Any datastore parameter that is used in a selection field, please add a field 'filter_version'
Enter '001' as version for all entries
When this datastore parameter is used, set up this 'Plain text' Filter:
[{ "fieldname": 'filter_versie', "filteroperator": 'contains', "filtervalue": '001' }]
Now, when you want to change the list of values, but not impact the current & old requests, follow these steps:
Add '002' in the field 'filter_version'. Do not delete '001' anywhere, as this will affect the older requests.
Open the field in the template-editor, and change the Filter to:
[{ "fieldname": 'filter_versie', "filteroperator": 'contains', "filtervalue": '002' }]
With this solution, you can freely choose which fields need a new set of values.
It is important to do this from setup, because adding it in later requires database-handling from our support team.
Dual filtering
If you want to perform 2 filters at the same time (for example, both a Version filter & a field-specific filter), follow this example:
[{ "fieldname": 'Version', "filtervalue": 'v001' },{"connector": 'and', "fieldname": 'Filter', "filtervalue": 'Q_Exams' }]
In the example above, the list of entries in the datatore parameter is fitlered against 2 rules:
Version = v001
Filter = Q_Exams
Filtering when the source are the Documents
Filter options
When creating a selection field, for example checkboxes, you have 3 options when settings the Documents filter. These are:
No filter: all documents are shown
On part: this option allows the filter against 1 (and only 1) document part. For example, where the Category = Test
Function: this new feature allows to make a filter against multiple data-elements. The filter is built using Javascript, some example can be found below.
Function (Javascript) Filter examples
Filter against 2 Document parts
In the example below, we only want to show the documents, that are valid under these 2 conditions:
Category 'equals' C1
Docs_Status 'is different from' Archived
So the internal labels of the document parts are : Category & Docs_Status.
This is the Javascript to be used:
var categorypartvalue = document.parts.filter(function (p) { return p.internalname === "Doc_Category"; }).map(function (p) { return p.value; }).join(""); var statuspartvalue = document.parts.filter(function (p) { return p.internalname === "Docs_Status"; }).map(function (p) { return p.value; }).join(""); return categorypartvalue === "C1" && statuspartvalue !== "Archived";
Note: ID a user selected a document in the past, and the user then changes this document's status to 'Archived', the changed document will no longer be shown in the list. This is as expected via the filters. But, the document that was selected in the past is still selected in the DB, but no longer shown.
Filter against current date
The example below checks in filter 1 if the field 'Status' holds 'Beschikbaar' and the field that holds a date in yyyyMMdd, lies after the current date:
return [ { "fieldname": "Status", "filtervalue": "Beschikbaar" }, { "fieldname": "Datum yyyyMMdd", "filteroperator": "greatherthanorequal", "filtervalue": CommonInterface.utcDateToString(new Date(),"yyyyMMdd") } ];
Last updated
Was this helpful?