How to sort assets automatically using a trigger

This tutorial shows you a simple way of using the Sort Asset Children trigger action to sort assets created under a particular root node automatically.

In this example, you configure Matrix to sort the assets in the tree by their descending Created Date value. Assets created under a specific folder automatically sort to the top of the asset tree rather than at the bottom.

Bottom sorting is the default asset creation behavior in Matrix.

Prerequisites

You must be a System Administrator to create or make changes to triggers.

As part of this how-to procedure, you need to create assets to which you can apply the sort trigger.

  1. Create a Folder asset named "Sort Assets" anywhere in your asset tree.

  2. Create three Standard page assets named "Page 1", "Page 2", and "Page 3".

  3. Move "Page 1" to be after "Page 3", so the pages are not in created date order.

Creating the Trigger

When you create a trigger, be clear when naming and describing what each trigger does. Over time you may set up hundreds of triggers, so having well-named triggers saves you time working out which one to change.

  1. Open System management  Trigger manager.

  2. Right-click and select New child  Trigger."

  3. Name the trigger "Sort assets by descending created date".

  4. Provide an (optional but recommended) summary of what this trigger does in the Description field. For example, "When you create an asset below the specified folder, sort it in descending order by its creation date."

  5. Set an (optional, but recommended) category of "Asset Sorting" in the Category field.

  6. Leave the Trigger view open and move to the next section to configure the trigger events, conditions, and actions.

Configuring the trigger event and action

Triggers work by combining different settings within the following configuration groups:

  • Events

  • Conditions

  • Actions.

For this specific example, the trigger sorts asset children (action) when an asset in a tree location (condition) is created (event).

  1. Select Asset Created in the Events section.

    The Asset Created event applies to any asset created through the Admin interface, Edit+, or through an asset builder.

  2. Click Save.

  3. Click Tree Location in the Conditions section.

  4. In the Tree Location condition, select the "Sort Actions" folder asset you created in the Prerequisites section.

  5. Click Immediate child only to only sort asset children directly below this asset.

  6. Click Save.

  7. Click Sort Asset Children in the Actions section.

  8. Click Save to display further Sort Asset Children configuration options.

  9. Set the following field values:

    Sort By

    When the asset was created

    Sort Direction

    Descending

    Sort Type

    Regular

  10. Click Save.

Actioning on Another Asset

So far, the trigger sort configuration acts on assets created below the "Sort Assets" folder instead of the folder itself.

To flip the trigger condition to act on the Folder asset, you use the Action On Other Assets option in the Sort Asset Children section.

  1. Click Action On Other Assets? in the Sort Asset Children section.

  2. Select Menu link from the Include linked parents? field to match the Link Type on the parent folder asset.

  3. Click Save.

  4. Click Enable on the Details view to activate the trigger.

Testing the configuration

Testing the configuration involves creating any asset below the "Sort Assets" folder and observing its behavior.

  1. Right-click on the Sort assets folder and create an asset (for example, a Standard page asset).

  2. Save the asset.

  3. Observe what happens in the asset tree:

    • The asset you created is automatically sorted by its created date and moves to the top of the tree.

    • The asset you deliberately changed the order of in the Prerequisites section is sorted correctly by its creation date.

Summary

You have configured a folder asset to automatically sort assets beneath it by their created date when you create a child asset beneath the folder.

© 2015-2020 Squiz Pty Ltd