Deep Dive: How to Use the 'Query Collection' Action

Ever bumped into the phrase "Query Collection" in Zenphi and wondered what exactly you're supposed to be querying? You are not alone! It is actually one of the most powerful, everyday actions in your workflow-building toolkit.

Let's break down exactly what it is, how to spot it, when to use it, and a common trap it will help you avoid.


First up: What exactly is a "Collection"?

Simply put, a collection is a list of repeating items. Instead of dealing with one single thing, you are dealing with a batch of things.

How to spot it: You will always know you are dealing with a collection in Zenphi when you see the [ ] icon next to an item's name!

A collection could be:

  • A list of text items (like a list of email addresses).

  • A list of numbers (like a list of invoice totals).

  • A list of files (like 3 different PDF attachments on an email).

  • A collection of records (like a list of 10 customers, where each customer has an ID, a Name, and an Email).

Whenever you need to interact with a specific part of that list, the Query Collection action is your best friend.


Top Use Cases for Query Collection

Here are the most common scenarios where this action shines:

1. When you need to Filter your list

Let's say you have a list of 100 customers, but you only want to find the ones under 20 years old.

  • How to do it: Enable the Filter toggle in the action, and set the condition to: When 'Age' is 'Less Than' 20. Zenphi will sift through the list and hand you a new, smaller list of just those younger customers.

2. When you want to Group items together

Imagine you have a big list of recent sales, but you want to organize them by the city where the purchase happened.

  • How to do it: Enable the Group By toggle and select your 'City' field. Zenphi will neatly bundle your big list into separate groups.

  • What you get back: Here is the cool part. For each group it creates, Zenphi will give you three things:

    • The Item you grouped by: The label of the group (e.g., "London").

    • The Count: The total number of items inside that group.

    • The Collection: A mini-list containing just those specific London sales.


📌 Note: How to Count Indexes

Before we look at the next two features, you need to know what an "Index" is. Whenever you are working with arrays or collections and it asks for an index, just remember: Counting always starts at zero.

  • The 1st item in your list is at Index 0.

  • The 2nd item is at Index 1.

  • The 3rd item is at Index 2.

Always subtract one from the position you want, and you'll get the right number!


3. Grabbing a specific range of items

Say you have 10 items in your list, but you only care about the 5th, 6th, and 7th items. You can tell Zenphi to skip the first 4 items and just grab the next 3.

  • How to do it: Select Range of items from the dropdown. Set your 'Start index' to 4 (because of the counting rule above!), and set your 'Number of items' to 3.

4. Picking the exact item you need

Sometimes you just need to pluck one specific thing out of the lineup. Under the 'Select items' dropdown, you can easily choose:

  • First item: Grabs the very first thing in the list.

  • Last item: Grabs the very last thing.

  • At specific index: Grabs one exact item from the middle. If you want the third item, you would choose index 2.


📌 Important Note: When a List Only Has One Item

It is incredibly common to have an output that is formatted as a collection (a list [ ]), even if there is only one item inside it.

Think of email attachments. The "attachments" field is always a collection, because an email can have multiple files. Even if a sender only attached one single file, Zenphi still hands it to you inside a collection (think of it like a single shoe sitting inside a shoebox).

If you pass that "box" to an action that is expecting just a raw file, the workflow will fault because you gave it a list!

The Fix: Use the Query Collection action. Go to the 'Select items' dropdown and pick First item. This takes the single file out of the list format so your next action can use it perfectly.