How To Sort Assets Automatically Using a Trigger
12 Jul 2018 For version 184.108.40.206
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.
- Go to the Trigger Manager and create a new Trigger called "Sort assets by descending created date".
- Start by doing the following:
- Enable Asset created in the Events section.
- Add a Tree Location condition in the Conditions section.
- Add a Sort Asset Children action in the Actions section.
- Then save the screen.
Your trigger should now look similar to this:
Configuring the Trigger Condition and Action
- 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.
- In the Sort Asset Children action, configure the following options:
- Sort By: When the asset was created
- Sort Direction: Descending
- Sort Type: Regular
- 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.
- To do that, we need to use the Action On Other Assets toggle on the trigger action, so go ahead and toggle that on.
- 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.
- 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.