How To Sort Assets Automatically Using a Trigger

Beginner

12 Jul 2018   By Bartek Banda   For version 5.4.5.0   Triggers

This tutorial will show you a simple way of how to use the Sort Asset Children Trigger Action to automatically sort assets by a certain order when they are created under a particular root node.

In our example, we'll want to sort the assets in the tree by their descending Created Date value. So when a new asset gets created under a specific folder, it automatically shows up at the top of the asset tree order rather than at the bottom.

The first thing we'll do is to create a Folder with a few Standard Pages underneath it to have something to test against.

Set up a simple asset structure similar to this:  

The intended effect we want, is that when a new Standard Page is created under this folder, for example when we create Page 4, it should appear at the top of this list.

Creating the Trigger

Let's create our Trigger.

  1. Go to the Trigger Manager and create a new Trigger called "Sort assets by descending created date".
  2. Start by doing the following:
    1. Enable Asset created in the Events section.
    2. Add a Tree Location condition in the Conditions section.
    3. Add a Sort Asset Children action in the Actions section.
  3. Then save the screen.

Your trigger should now look similar to this:

Configuring the Trigger Condition and Action

  1. Next, select our Folder asset we created previously as the root node for the Tree Location condition. Also make sure to tick the Immediate child only option, as we only want to sort children that are directly under this folder.
  2. In the Sort Asset Children action, configure the following options:
    1. Sort By: When the asset was created
    2. Sort Direction: Descending
    3. Sort Type: Regular
  3. Save the screen.

Actioning on Another Asset

The last thing we need to do, is to make sure that the Action actually fires on the parent Folder asset, not the asset that gets created. We want to sort the children of the Folder asset, not the children of the newly created Standard Page asset that fires the Trigger.

  1. To do that, we need to use the Action On Other Assets toggle on the trigger action, so go ahead and toggle that on.
  2. Here we can simply just configure 1 thing, which is the Include Linked Parents field. Set that to TYPE_1 (or TYPE_2 if your parent asset will be a Type_2 link type.

  3. Save the screen.

That should be it. Make sure you also Enable the trigger so that it fires at the next asset is created.

Now if we simply right-click on our Folder asset and select any asset to create, for example a new Standard Page, it will automatically be placed at the top of the tree order. Any other assets under the same folder will also be automatically sorted at the same time.

Write a Tutorial

Help us build a healthy library of useful tutorials for the Matrix Community.

Get in Touch

The Latest

Let Us Know What You Think

Let us know if you spot any errors or if you have any ideas on how we can improve the Matrix Community Website.

Contact Squiz for Demo

Let us show you the true power of Squiz Matrix by giving you a personalised demonstration.