Standard/Best Practices
Use Cases
Connecting to on-prem systems

List Helpers (adv.)

Combining and sorting lists of project tasks

This tutorial will take you through how you can use the Concatenate and Sort Objects operations in the List Helpers connector to combine and sort lists of tasks taken from projects in a project management tool, such as Asana.

In this tutorial you will be introduced to:

  • The Asana connector

  • The List Helpers connector

  • The Loop connector

  • The Data Storage connector

  • The Text Helpers connector

What we will be achieving here is:

  1. Get lists of tasks from two separate Asana projects

  2. Combine (using concatenate) these into one list

  3. Sort (using sort objects) these tasks in date order - with earliest due at the top

  4. Use the loop collection, data storage and text helpers connectors to format these into a batch message which lists the tasks and their due date one-by-one

  5. Send this batch message to a Slack channel so as to notify about the tasks which are due, with the earliest tasks listed first

The end result in Slack will look something like:

In Tray, the complete workflow looks like this:

Step 1 - List the Asana tasks by project

For each of the Asana steps above you will need to set the operation to List Tasks and choose the project.

This will create the two lists that we want to combine. When a workflow has been run and you are inspecting the debug output of a listing of Asana tasks, you will see that there is a lot of data associated with each task:

Step 2 - combine the lists

Set the first list helpers step to Concatenate and choose the two Asana steps as Lists 1 and 2.

Step 3 - sort list by date

Set the second list helpers step to sort objects, the list to $.steps.list-helpers-1.result and choose due_on as the key. We know to use due_on because the output schema from either of the Asana steps lists it for us (you can also see it in the above list task output screenshot from Step 1):

Step 4 - loop through each task to create individual messages

Add a loop connector and set the input list as $.steps.list-helpers-2.result

Get Asana project

For each result you should get the Asana project name using the Asana Get Project operation, using $.steps.loop-1.value.projects[0].id to get the id for the project which the current task comes from:

Create message

The Create messsages step uses a data storage connector to create and store the indvidual message for that task. Do this by using the Append to List operation and make sure the Create if missing box is ticked:

Keep the scope as 'Current Run' and set the Key as 'message' (this means you will be creating a list of 'messages')

Note that the Value is kept as 'string' type and uses { } to allow for use of jsonpaths to grab the necessary data for each message:

The '{$}' task from the '{$}' project is due on {$.steps.loop-1.value.due_on}

This would create a message such as "The 'Deploy to Production' task from the 'Shareable Workflows' project is due on 2018-08-05"

Step 5 - Get messages

The final stage is to batch the individual messages together.

The Get messages step uses a data storage connector to get all the stored messages:

These are returned as an array:

Step 6 - format the batch message with a Text Helper

We can then pick these up and format them using the Text Helpers (Create batch message) connector. This uses the Concatenate operation and grabs $ to go through the individual messages.

The key step to formatting the message correctly here is, in the Separator box, hit the 'Enter' key on your keyboard to add an empty line. This will ensure that each message takes a new line.

Step 7 - send the message to Slack

The final stage is to choose a Slack channel to send the message to:

The message is grabbed from the previous step with $.steps.text-helpers-1.result

And the final message sent to Slack should look something like this:

Example 2 - deleting items from a list

The Delete items from list operation can be used to create a list and delete certain items from it which match certain conditions:

The above example shows how you could remove a project with a particular title from a list of Asana projects.

Another way to use this might be to change the Comparison type to 'Contains' and the Value to 'test' in order to filter out any projects which are only test projects.