DataError: Function 'sort' finished with error! Invalid array

:bullseye: What is your goal?

Description: I am building a rule-based career recommendation system. I am fetching student scores from Google Sheets and attempting to identify the top two subjects to map them to specific careers

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

The Workflow:

Google Sheets: Fetching student data (Maths, Science, etc.).

Set Variable: Creating a JSON array of collections: [{“subject”: “Maths”, “score”: 85}, …].
Parse JSON: Parsing that string into a structured array.
Set Multiple Variables: Using sort() and get() to find the highest scores.

Here, it doesn’t give me the Output as Top_subject1: Maths , Score: 100 and SecondSubject2: Science, Score: 90

:clipboard: Error messages or input/output bundles

The Error: Despite the JSON being valid and the module being set up, the Set Multiple Variables module returns:

DataError: Failed to map ‘0.value’: Function ‘get’ finished with error! Function ‘sort’ finished with error! Invalid array.

Formula Used: {{get(sort(5.Array; “desc”; “score”); 1)}}

:link: Create public scenario page

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

1 Like

Hey there,

Two issues. First, you shouldn’t be mapping the entire [bundle] coming from the module.

Second, the parse JSON module is not returning an array as output. So those formulas won’t work.

Either the array is already iterated and you are getting individual bundles per item inside, or there never was an array to begin with. So check your data and what each module is giving as output.

Hi @VerbaliTongue ,

Please ensure that you are using the correct syntax for the sort() function in Make.com. The format currently used inside the sort() function is not valid. Below are the correct formats as per the official Make documentation.

  • sort( Contacts[ ] ; name )
    Sorts an array of contacts by the name property in default ascending order.

  • sort( Contacts[ ] ; desc ; name )
    Sorts an array of contacts by the name property in descending order.

  • sort( Contacts[ ] ; asc ci ; name )
    Sorts an array of contacts by the name property in case insensitive ascending order.

  • sort( Emails[ ] ; sender.name )
    Sorts an array of emails by the sender.name property.

For more details on how the sort() function works, please refer to the official documentation linked below.

Best regards,
Msquare Automation
Platinum Partner of Make
@Msquare_Automation