Skip to main content

Automation Email - inserted grid - date order issue


Forum|alt.badge.img+2

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

Zack_S
Forum|alt.badge.img+15
  • Inspiring
  • 95 replies
  • September 8, 2023

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-summary/td-p/147406

 


Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • 5 replies
  • September 8, 2023

Thank you very much ðŸŒŸ


Forum|alt.badge.img+2
  • New Participant
  • 3 replies
  • October 26, 2023
Terri_Martin wrote:

Thank you very much ðŸŒŸ


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


Forum|alt.badge.img+2
  • Author
  • Participating Frequently
  • 5 replies
  • January 22, 2024
epatten wrote:

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
            }
        )
        
}

Forum|alt.badge.img+6
  • Known Participant
  • 12 replies
  • August 28, 2024

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


Reply