Table of Contents

SortItemsValve

Note

Valve to sort items from the current item set. Supports multiple sorting rules, standard alphabetical sorting (both ascending and descending), and custom javascript sorting expressions. By default it will sort in ascending alphabetical order based on the configured item properties.

Properties

Name Description Default value Mandatory Supports property expansion
rules An array of the sorting rules. N/A Yes No

Sorting rules properties

Name Description Default value Mandatory Supports property expansion
property The item property to sort on N/A Yes No
desc If descending order should be used. Valid values are "true" or "false". false No No
comparator_expression An optional javascript expression to sort on N/A No No

Example Configurations

Multiple rules

This is an example configuration with two rules, so the items will first be sorted based on their givenName property, and if it is equal, they will then be sorted based on their sn property.

{
    "id" : "20693793-febb-433d-9d1a-de32b6565692",
    "name" : "SortItemsValve",
    "enabled" : "true",
    "config" : {
        "rules" : [ {
            "property" : "givenName"
        }, {
            "property" : "sn"
        } ]
    }
}

Reverse order

In this example, the desc config parameter is used for a reverse, or descending alphabetical order.

{
    "id" : "20693793-febb-433d-9d1a-de32b6565692",
    "name" : "SortItemsValve",
    "enabled" : "true",
    "config" : {
        "rules" : [ {
            "property" : "givenName",
            "desc" : "true"
        } ]
    }
}

Custom expression

In this example, the config parameter comparator_expression is used for a custom sort order. Here it checks if the givenName value compared at the items has a value "shouldBeFirst". If so, it should be first in the order. Otherwise, it falls back to a standard alphabetical sorting. This can be combined with the desc parameter to reverse the order if desired. The comparator_expression is a javascript expression that should evaluate to an integer such that it can sort the items. The only scope variables are a and b which are the items being compared. For more information on how to write javascript expressions for sorting, see the MDN reference.

{
    "id" : "20693793-febb-433d-9d1a-de32b6565692",
    "name" : "SortItemsValve",
    "enabled" : "true",
    "config" : {
        "rules" : [ {
            "property" : "givenName",
            "comparator_expression" : "a == 'shouldBeFirst' ? -1 : b == 'shouldBeFirst' ? 1 : a.localeCompare(b)"
        } ]
    }
}