Help

Re: Automation Email - inserted grid - date order issue

1368 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Terri_Martin
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi Aweome Airtable Community. 

Please could you help me understand what I am doing wrong or enlighten me as to why this is happening?

I have attached a sample of the Automated email that is sent to our client with a copy of all their appointment in a grid.

The issue is that the appointments do not show up in the correct date order for easy checking, and we have had complaints.

Why does this happen?  Is it using a different field so sort the appointments?

Thank you in advance for the advice and help

 

 

 

 

 

5 Replies 5
Zack_S
8 - Airtable Astronomer
8 - Airtable Astronomer

Hi @Terri_Martin, you would need to use the scripting extension for this. This thread has a good example for you - https://community.airtable.com/t5/automations/sorting-linked-records-in-automation-script-for-summar...

 

Terri_Martin
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you very much 🌟

Hi! Did you ever solve for this? Did you build a script? Struggling over hereeeee lol

Once I sorted out the Record ID Variable, it seemed to work but I still get some lines out of order.  At the moment I am using this code - 
 
 
// get recordId that triggered automation from
// input variables
let recordId = input.config()['recordId'];

// Change this name to use a different table
let peopleTable = base.getTable("ClinicianMonth");

let registrationsTable = base.getTable('Appointments');

// Prompt the user to pick a record 
// If this script is run from a button field, this will use the button's record instead.
let record = await peopleTable.selectRecordAsync(recordId)



    // get cell with linked records 
    let linkedRegistrations = record.getCellValue('Appointments');

    if (linkedRegistrations) {

        for (let registration of linkedRegistrations) {
            // get the full linked record info
            let registrationRecord = await registrationsTable.selectRecordAsync(registration.id);

            registration['date'] = registrationRecord.getCellValue('Start time')
        }

        // sorts list by date from earliest date to latest date
        linkedRegistrations.sort((a, b) => (a.date > b.date) ? 1 : -1)


        // remove the added date attributes after sorting
        for (let registration of linkedRegistrations){
            if (registration.date) {
                delete registration.date;
            }
        }

        
        // output.inspect(linkedRegistrations)

        await peopleTable.updateRecordAsync(
            record.id,
            {
                Appointments: linkedRegistrations
            }
        )
        
}
Anne_Gonzalez
6 - Interface Innovator
6 - Interface Innovator

Good news! This is now possible without scripting. Airtable added "sort list" as an automation action.  You can sort by any field.