How to sort an array after an aggegator

:bullseye: What is your goal?

Purge old files on Goodgle Drive keeping only the latest verstion.

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

I have an iterator after an aggregator that is not working. The iterator had a sort option on the input from the aggregator that collapse everthing into one bundle. SO I though that I could take the ouptut of the aggregator which is an array of objects each with filename, fileid and createion date, and then sort by date. Then this would still be a valid array for the iterator. But if the sort is in the iterator itself I just get an input which is a long text of the collapsed file contents not indivitual file collections which could be processed by the iterator and passed to filer for the first file in the sorted list. The intent is to get all files with a name match on GoogleDRive and then sort by date and use the filter to pass the file index of old files to Google File Delete leaving only the most recent on the drive.

1 Like

Hi @Malcolm_Sokol ,

To help us investigate this further, could you please share additional details such as screenshots of the module mappings and the scenario setup? If there are any errors please include those as well. This information will allow us to better identify the root cause of the issue and troubleshoot it more effectively.

Best regards,
Msquare Automation
Platinum Partner of Make
@Msquare_Automation

Hello,

My best guess would be to use the “sort” function in Make before starting the iterator, that way you can get to the values that you want organized in the correct format. When mapping go to the “Functions for Working with Arrays” tab and select Sort and then map the iterator input after sorting.

I hope this helps.

2 Likes

To add to this, probably need to also specify the key to sort by. Here’s the docs for more info on using it.

Yep .. I think the “collapse” happens because you’re trying to sort inside the Iterator. Sort the array before the Iterator, then iterate the sorted list.

Flow:
Search files → Array Aggregator → (sort step) → Iterator → filter “skip first item” → Delete file

After sorting newest → oldest: Keep the first item (newest), Delete the rest (old)

If you tell me which date field you have (createdTime or modifiedTime), I can tell you exactly what to sort by.

1 Like