Filtering When the Source Is Documents

When creating a selection part (such as checkboxes, dropdown lists, or typeahead fields) you can configure filters that limit which Documents are shown as selectable options. The filtering system provides three modes, depending on how simple or advanced the required logic is.


Filter Options

Filter Mode

Description

No filter

All documents are shown. No conditions are applied.

On part

Filters on one single document part (only one can be used here). Example: only show documents where Category = Test.

Function (JavaScript)

Allows advanced filtering based on multiple document parts and custom logic. Useful when combining conditions or evaluating dynamic date values.


Function (JavaScript) Filter Examples

The Function filter mode allows complete programmatic control over document filtering. You can check values of multiple document parts, combine rules, and return true or false to indicate whether a document should be shown.

Below are the most common use cases.


1. Filter based on multiple Document parts

Goal: Only show documents that match both of the following conditions:

  1. Category equals C1

  2. Docs_Status is not equal to Archived

Internal names of the document parts:

  • Doc_Category

  • Docs_Status

JavaScript example:

var category = document.parts
    .filter(function(p) { return p.internalname === "Doc_Category"; })
    .map(function(p) { return p.value; })
    .join("");

var status = document.parts
    .filter(function(p) { return p.internalname === "Docs_Status"; })
    .map(function(p) { return p.value; })
    .join("");

return category === "C1" && status !== "Archived";

Important note

If a user previously selected a document and later the document’s status changes to Archived, the document will no longer appear in the selectable list due to the filter. However, the previously selected document remains stored in the database. This is expected behaviour, as filtering only controls visibility—not stored values.


2. Filter against the current date

You can also filter documents based on the current date.

Goal: Show only documents where:

  • The Status part is Beschikbaar

  • AND a date field (stored in yyyyMMdd format) is greater than or equal to today

JavaScript example:

return [
    { "fieldname": "Status", "filtervalue": "Beschikbaar" },
    {
        "fieldname": "Datum yyyyMMdd",
        "filteroperator": "greatherthanorequal",
        "filtervalue": CommonInterface.utcDateToString(new Date(), "yyyyMMdd")
    }
];

This example uses the same format that OLM stores dates internally, ensuring correct comparison behaviour.


General Notes

  • JavaScript filters allow full flexibility but require correct internal part names.

  • Make sure the document part internal names (internalname) match exactly.

  • For date comparisons, always convert the current date using:

CommonInterface.utcDateToString(new Date(), "yyyyMMdd")

Last updated

Was this helpful?