Map() not extracting data

:bullseye: What is your goal?

To list all tasks in our Tasks list every morning, and if any are missing one of our necessary fields, fill them out.

:thinking: What is the problem & what have you tried?

This scenario ran successfully on Monday, July 20th. It was turned off after that. I ran it again on July 22nd and it threw an error in the filters (see error details in section below). Examining it, I found that the map() function is not extracting a field based on the name for some items. I previously used:
{{first(map(46.array; "id"; "name"; first(split(last(split(29.name; "(")); ")"))))}}
and variations of it like:
{{map(first(map(toArray(first(map(46.array; "custom_fields"; "name"; first(split(last(split(29.name; "(")); ")"))))); "value"; "key"; "Payroll Processor")); "id")}}

I tried finding the ID based on the name and then {{custom_fields}} based on the ID. It worked once and then it didn’t work again.

The name is not incorrect since the tasks that have this name in (the format we use is “Task Name (Biz Name)”) have also been created automatically. Regardless, I tried manually using the map() function (instead of fetching the name of the business from the task name, I copied it directly from ClickUp or directly from the Array Aggregator module), that didn’t work either.

:clipboard: Error messages or input/output bundles

“Failed to evaluate filter ‘0-1’: Function ‘first’ finished with error! Function ‘map’ finished with error! Function ‘toArray’ finished with error! ‘{empty}’ is not a valid collection.”

Basically, the inner map() function that’s trying to find the id based on the name is failing to find it for some reason.

:camera_with_flash: Screenshots (scenario flow, module settings, errors)

Scenario flow:

Filter between the router and the first route (Add Business Relationship)

Iterator on the second route (Add Client Relationship)

Hey there,

none of your screenshots shows the filter from the error message. The toArray() formula that you do show has a map() formula inside of it, which returns an array, not a collection. Also the error shows that whatever was inside was empty and not a collection, so you can test just that and see what breaks it.

Also this is an extremely convoluted formula. What are you checking for here? Looking for tasks where a specific custom field is empty? List all tasks module → router → filter that checks that the specific custom field does not exist → edit a task moduel to set it. Bonus points for adding the filters inside the list all tasks module so it returns only items where any of the fields don’t exist.

Thank you for your reply!

Here is the filter with the error.

It let 7 bundles through (and they successfully completed) before failing on this one.

toArray() is there because I was building it from the ground up and {{custom_fields}} came out as a collection. Then, to be able to extract the Contact from the Custom Fields, I transformed it into an array to use the map() function again.

This is what the full formula in the filter looks like:

Also this is an extremely convoluted formula. What are you checking for here? Looking for tasks where a specific custom field is empty?

Yes.

List all tasks module → router → filter that checks that the specific custom field does not exist → edit a task moduel to set it.

That is what I’m doing but I’m also checking if the Businesses item (that’s in the aggregated array) has that field. Sometimes the task won’t have an Accountant attached to it and then we’ll check the Businesses item and that one won’t have an Accountant attached either. To prevent the API calls from failing I added the filters:
Accountant doesn’t exist in task + Accountant exists in Business item

Bonus points for adding the filters inside the list all tasks module so it returns only items where any of the fields don’t exist.

I haven’t found a way to do that with ClickUp yet. I’ve tried using “List Filtered Tasks” but whatever setup I create, I just get all tasks or 0 tasks.

But I’m trying to solve this issue at the moment, I can optimize the module for this later on.

But you dont need to aggregate the tasks and them and then check if the aggregated array has specific tasks or not.

Custom fields coming out as a collection means you can access and map the specific custom field you need directly in the filter. There is no need to overcomplicate it by turning the collection in an array, then searching the array for the specific custom field.

And here is a screenshot of the list tasks module:

When there is no list selected, you will need to use the custom field IDs, but once you select a list, you can just pull them.

But you dont need to aggregate the tasks and them and then check if the aggregated array has specific tasks or not.

I am aggregating the Businesses list in the beginning. I am doing this because I want to filter Business items by name (and no ClickUp module allows that, only custom fields or other default fields like status and due date). If I were to list all Businesses for each task, the scenario would be really inefficient.

I am not aggregating the Tasks list at all.

Thank you for the input about the filters, so far I’ve only ever mapped the list ID (and then tried mapping the custom fields IDs as well, but always got either all or no tasks) but now I see that I can do that as well, this is really helpful!

The reason I’m aggregating the businesses list is that I want to have the businesses only listed once. Some tasks will have a Business connection but others won’t so I’m search for the business item using the name of the business. I checked the filters that you just helped me with and I still can’t filter by name, only Assignee, Due Date, Tags, Status and then Custom Fields.

Please see video below of the run. I hope it will help to visualize what I’m trying to do and where the issue happens.

I would like to try this as well:

Custom fields coming out as a collection means you can access and map the specific custom field you need directly in the filter. There is no need to overcomplicate it by turning the collection in an array, then searching the array for the specific custom field.

But with what I’m doing, the collection of custom fields is not coming up. I searched for the name in the end of the video to show you that an item with that name exists in the aggregated array and that it has an accessible collection of custom fields.

So you are listing all businesses, grouping them in an array, listing all tasks, and if a task name matches something in the businesses array and it has a custom field missing, it has to pull the values from the businesses array. Is this correct?

Yes, that is correct.

Then, when a business item is found, I use that information to fill out the task item. E.g. if a task didn’t have an Accountant attached to it, I find the Accountant attached to the Business item for that task and then attach the same Accountant to the task.

You can add a filter after the module that lists all clients and check if the name matches there.

Anyway, the formula you have should work, but I don’t see the syntax properly in the video. Could be an empty space somewhere breaking it, or one too may closing brackets closing a function too early.

I just did a local test with my data and this formula worked:

{{first(map(3.array; "custom_fields"; "name"; first(split(last(split("test (Call)"; "(")); ")"))))}}

In my case the task name was Call and it did find it and pull it’s custom fields.

I just tried that formula and it works with Call. It also works for some of the tasks that I already have, but for others it doesn’t.

This is the full testing setup that I’m using, so no other filters here:

I would share a video here as well but the data is sensitive. I tried creating a new item with a non-identifiable name but it worked as it should every time!

I have now tried changing the name to a task that wasn’t working to “Ball” temporarily and it worked. When I put the original name back in, it didn’t work again. I also tried trim(), ascii(), replaceEmojiCharacters(), replace() with regex on the name of the task before map(), text parser instead of split() for extracting the name of the business, text parser’s replace module, nothing worked. If there are any other ways to transform the text to try to escape this, please let me know.

And now, going through all of this, I see that this seemingly happens only for Businesses whose name has a comma in it. Could this be breaking the whole flow? And why?

When I search the aggregated array for that name, it shows up no problem. But when I try with map(), it doesn’t work.

A few things come to mind:

  1. I could group all tasks for one business (all tasks that have the same Business Name in brackets) and then do the actions on all of them at once - find the Business item and then iterate through the array of tasks for that Business. I’m not quite sure how that would work but it sounds doable to me.
  2. I’d add an if-else module that would get the Business item (either by finding it from scratch with List All Tasks for the Businesses list if task doesn’t have Business item connected or just taking the ID if it’s connected). From here I’d have all the Business item’s info that I need and I’d just route it where it’s needed. This might be a drag because the tasks that I’m updating are recurring tasks. ClickUp is not transferring relationships in our recurring tasks (even though Relationships is checked in the Recurring tasks options) so we’re doing it this way through Make.
  3. Maybe a combination of these two somehow?

Oh yeah sorry. I completely missed that. It’s the map() function causing the issue. When you put a comma separated list in there it treats it as separate arguments to check against, not one whole string.

So to avoid this, put a list all tasks module there and list the tasks, then have a filter after it that only allows tasks where the task name matches.

Amazing, thank you so much for all of your help!

I was able to resolve with the if-else module before the task listing without changing anything else

and it works flawlessly now!