Sorting Array Before Next Module

:bullseye: What is your goal?

I store my data in GDrive and the folder structure is something as below.

Root > Month > Region > Site

In each Site folder, I have 7 PDF files but I only want to merge two PDF files that contain “Doc” and “Checklist” in their file names. I use ILovePDF Module for merging the PDF files.

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

I have created a template which works (as per the screenshot). However, I want to make sure the order of the mergedfile is as per my requirements. Hence, I need to be able to sort the output array before being processed by ILovePDF.

In the screenshot, I included the debug output and basically what i want to achieve is that Output Bundle 1 Array has two collection. The first one should be the filename 1 - Dok Test 1.pdf. How do I sort these collections before going to the next module?

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

This is achievable in Make as you already have the order in the Array in just one bundle. It seems that the filename order is already numbered 1 and 2 which is extremely helpful. All you would need to do is add a “Set Variable” or “Set Multiple Variables” module before the ILovePDF module depending on how it needs to go. In that variable find the “sort” function (it is under the “Functions for Working with Arrays” tab, that looks like a table) and then map the Array and then use “filename”

sort(array; filename)

This should solve your problem.

Welcome to the Make community!

To do this, you can use the built-in function:

  • sort
    sort(array; [order]; [key])

This function may have also been covered in the Make Academy tutorials — refer to the Make Academy Course Overview to learn more.

Here’s an example of how you can use this function:

{{ sort(array; [order]; [key]) }}
:high_voltage: Make Input Markup: Copy-paste the above into the field, including start/end curly brackets for it to import as intended :warning:

e.g.:

Hope this helps! If you are still having trouble, please provide more details.

— @samliew
P.S.: investing some effort into the tutorials in the Make Academy will save you lots of time and frustration using Make!