Expand my Community achievements bar.

SOLVED

How to know if a list is empty

Avatar

Level 1

Hello,

I'm working on a workflow where I have to purge lists. I'd like to know if there is a way to know if a list is empty (while still keeping its structure).

Best regards,

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

@mtraverso1,

You can use the built-in @COUNT function to count the number of records in the list. If the count is 0, then the list is empty.

Here are the steps to check if a list is empty:

  1. Create a new query activity in your workflow and select the list you want to check.
  2. In the query editor, add a new expression column and enter @COUNT() as the expression. This will count the number of records in the list.
  3. Save the query and run it.
  4. Once the query is finished, open the console tab in the workflow and look for the output of the query. If the count is 0, then the list is empty.

If the count is greater than 0, then you can use a separate activity, such as a delete data activity or a purge data activity, to remove the records from the list.

By using this method, you can check if the list is empty while still keeping its structure intact.

View solution in original post

6 Replies

Avatar

Community Advisor

Hi @mtraverso1,

 

After the read list activity, Use a test activity to check the record count on the list. Example condition: vars.recCount >0 

Thanks, Sathees

Avatar

Level 5

Hi @mtraverso1 

 

This is my actual workflow that does this:

alnavarg_0-1681462051271.png

 

The first two steps are self-explanatory. The query is just querying the same record set for 0 records, but I also put all the additional data onto the schema that came off the schema when I first loaded it. I think this is so the new List has the exact same structure as the old list. Make sure you put the targeting dimension on there too.

alnavarg_1-1681462051406.png

 

Then I just save the new list as the same name as the old list

alnavarg_2-1681462051282.png

 

 

 

Avatar

Community Advisor

HI @mtraverso1 ,

If you want to purge the list and need to insert the new records, you can enable 'Purge and reuse the list if available' option in List Update activity.

 

Or if the requirement is to check whether the data is available in a list, and If yes, then you need to purge all records in the particular list and keeping the same structure in it, then you can try the below workflow set up

ParthaSarathy_0-1681716544173.png

Read List: Select your List

ParthaSarathy_1-1681716603332.png

Test activity: As mentioned by Sathees, you can use vars.recCount > 0 to split based on record count.

ParthaSarathy_2-1681716702385.png

Split Activity on records available transition:

Limit the selected records > Activate random sampling > Limit Maximum size: 0 > Finish

ParthaSarathy_3-1681716838347.png

In List Update, Select the same List and enable purge the list checkbox.

ParthaSarathy_4-1681716925394.png

So now the workflow checks whether your List has any records, And if records exist, then it will purge the list data but the structure of the list will be same as before.

 

Avatar

Level 7

Try to use an JS Activity that tries to retrieve the value 0 of the list 

 

Avatar

Correct answer by
Employee Advisor

@mtraverso1,

You can use the built-in @COUNT function to count the number of records in the list. If the count is 0, then the list is empty.

Here are the steps to check if a list is empty:

  1. Create a new query activity in your workflow and select the list you want to check.
  2. In the query editor, add a new expression column and enter @COUNT() as the expression. This will count the number of records in the list.
  3. Save the query and run it.
  4. Once the query is finished, open the console tab in the workflow and look for the output of the query. If the count is 0, then the list is empty.

If the count is greater than 0, then you can use a separate activity, such as a delete data activity or a purge data activity, to remove the records from the list.

By using this method, you can check if the list is empty while still keeping its structure intact.

Avatar

Administrator

Hi @mtraverso1,

Were you able to resolve this query with the help of the given solutions or do you still need more help here? Do let us know. In case the given solutions were helpful, then kindly choose the one that helped you the most as the 'Correct Reply'.
Thanks!



Sukrity Wadhwa