Open Navigation

List Helper

Perform quick manipulations to an array of data.
On This Page

Overview

The Tray 'List Helpers' connector allows you to quickly create and manipulate lists based on arrays of data generated by other services and connectors in your workflows.

Amongst other things, this allows you to combine data from multiple sources, sort it, extract certain values, find common items, create batches for processing...

Note some list actions you wish to carry out will require use of the Append to List operation found in the Data Storage connector. This is illustrated in the first example below.

Example - combining and sorting lists of project tasks

This example will take you through how to use the Concatenate and Sort Objects operations.

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:

batch-slack-message

In Tray, the complete workflow looks like this:

list-example-1-workflow

Step 1 - List the Asana tasks by project

list-asana-tasks

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:

list-asana-tasks-output

Step 2 - combine the lists

asana-combine-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

list-sort-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):

asana-schema-due-on-1

Step 4 - loop through each task to create individual messages

loop-through-tasks

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:

asana-get-project

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:

create-individual-message

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 '{$.steps.loop-1.value.name}' task from the '{$.steps.asana-3.data.name}' 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.

create-batch-message-workflow

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

get-messages

These are returned as an array:

messages-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 $.steps.storage-1.value to go through the individual messages.

create-batch-message

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:

slack-send-message

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:

batch-slack-message

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:

delete-item-from-list-1

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.

Operations complete

Below you can find a list of the available List Helper Operations.

Was this article helpful?
Yes
No
On This Page