Lists within a list

Using the “CRM” Blueprint / calendar page

I’m trying to filter a list within a list and getting stuck on the logic to use.

The list “calendarDate” is a list. Each item in calendarDate contains three lists (Tasks, Touchpoints, autoTasks) – I am trying to target the list “autoTasks” and within that match the “type” property to “hazard”.

“calendarDate” List

contains “autoTasks” List

contains property “type” = “hazard”

I have tried many variations of filtering and loops, but cannot seem to make this work. I’ve tried about ten variations – this is the latest, which I hope shows what I’m trying to do:

If calendarDate is a list, then why are you treating it as an object by retrieving a value for a property:

I tried it this way, still no success

“autoTasks” is not a list, it is just a string:

I think you wanted to get the “autoTasks” property from “j” ?

Suggestion: Use the print block to output/print the structure of the calendarDate variable. Based on what you see there, follow the structure in your processing logic.

I’ve been using the print block to see the structure of the calendarDate variable, it contains a list of properties and arrays (of which autoTasks is one)
Latest attempt:

This logic:

  • iterates over the list of items in calendarDate
  • for each item j (which is a list) in calendarDate:
  • it gets the value of the autoTasks.type property (btw, you can use the dot notation now in a single “get property” block) and checks if the value is hazard
  • if the value is hazard, it returns true, otherwise false
  • in the end, you will end up with a list of true and false values.

Is this what you need?

If not, please share the output of print for calendarDate and describe the end goal.

I’d like to return a list of objects from each of the autoTasks lists where the “type” = “hazard”

In each item of calendarDate, I need to find the autoTasks list and then inside of that list, I need to evaluate the “type” = “hazard”. I’d like to return a list of objects where the “autoList.type” = “hazard”.

The print of calendarDate looks like this:

It would help to see an expanded version of the autoTasks sublist :wink:

If you need to return a list of objects, then right here (see below) you should be returning not a result of the comparison (which is a boolean) but the actual object (item) if the condition is true.

To do what you want use the “test/ if true / if false” block. Also, here’s a video describing how list filtering works:

Thank you for the video link. I re-watched it and came up with this:

However, the result is empty.

The structure of the autoTasks list is below:

You’re still returning a boolean value and not an object.

You could copy/paste from the DevTools console into here. It would help to see what the actual hazards variable contains in the end.

Hope I’m doing this right:

[
{
“created”: 1644367040000,
“dueDate”: 1644453433000,
“description”: “There’s a snake in my boot”,
“ownerId”: null,
“type”: “hazard”,
“assignedTo”: null,
“name”: “Hazard Investigation”,
“___class”: “AutoTasks”,
“typeID”: null,
“department”: null,
“updated”: 1644367598000,
“objectId”: “A91043A0-ABF9-4572-8048-28AF3B539356”,
“status”: null
}
]

Yes, you copied it correctly :slight_smile: However, I am asking to see what this prints:

Ah, apologies. Here it is:

image

This is what I would do to debug further:

After trying some more, I’ve managed to get the filter to refine my list down to the items that have the “autoTask” property and the filter item “j” shows these individually, however I can’t seem to get these individual results filtered to “type = hazard” and assigned to a variable. This variable “result” comes back undefined.

Can you point me at why I can’t get this property type logic to work?

@Neil_Campbell

Hard to say where exactly the issue happens. Could you create an extra page with a minimum of logic to reproduce that?