How to delete a record from Airtable when an event is deleted from Google Calendar

This topic was automatically generated from Slack. You can find the original thread here.

La Lodge : Hello,
I am new to the no-code and automation world. My level is beginner.

I am currently experiencing a problem with my Google calendar -> Airtable workflow.

Indeed, when a Gcal event is cancelled, I would like my associated Airtable record to be deleted from my database.

I think I succeeded in setting up my workflow, but at the very end, I am asked for the Record ID associated with the event.
I would like the Record ID to be a dynamic data, because it will never be the same record that will be deleted.
How can I set this up? Is it possible?

Thank you in advance :+1:

Leo : Hello , how the Airtable records created, are they created when a Google Calendar event created from a Pipedream workflow?

I’m asking this because if the Airtable Record is created from Pipedream workflow, you can add a step to store the created Record’s ID and the Google Calendar Event ID into Pipedream’s Datastore.

And then on your workflow to delete the record, when a Google Calendar is deleted, you can use the deleted Google Calendar ID to search its Airtable Record ID from the Datastore, then use that Airtable Record ID to delete the Airtable Record

La Lodge : the event in Gcal is connected to airtable. I don’t use Pipedream to create the event in Gcal.
But i’m looking for a solution to delete automatically the record when the event in Gcal is cancelled :+1:

La Lodge : My problem is that i can’t find a dynamic Record ID. I Have to write the correct Record ID to delete it…

Leo : Hello , apologize for the late response. May I ask how can you determine the link between an Airtable record and a Google Calendar? Are you comparing the Record’s name and the Google Calendar event name?

La Lodge : On the airtable record, I import also the Gcal event ID

Leo : you can add an Airtable Custom Code action to get the Record ID that linked to your Google Calendar.

1/ Add Airtable action > Use any Airtable API in Node JS (1st image below)

2/ On the action added, there’s an existing code that allow you to fetch records from air table using filter. You can use this to get the record that linked to your Google Calendar Event ID (2nd image below)

I have updated the code to enable filter as below, but you need to fill in one things:

  1. Replace the <fill airTableField .e.g name> part with the column in Airtable that containing your Google Calendar Event ID
module.exports = defineComponent({
  props: {
    airtable: {
      type: "app",
      app: "airtable",
    },
    baseId: {
      type: "$.airtable.baseId",
      appProp: "airtable",
    },
    tableId: {
      type: "$.airtable.tableId",
      baseIdProp: "baseId",
    },
  },
  async run({steps, $}) {
    const Airtable = require('airtable');
    const base = new Airtable({apiKey: this.airtable.$auth.api_key}).base(this.baseId);

    const data = []
    
    const airTableField = '<fill this .e.g name>'
    const googleCalendarEventID = steps.trigger.event.id
    await base(this.tableId).select({
      filterByFormula: `${airTableField} = ${googleCalendarEventID}`
      // pass optional config parameters here
    }).eachPage(function page(records, fetchNextPage) {
        // This function (`page`) will get called for each page of records.
        records.forEach(function(record) {
            data.push(record._rawJson)
        });

        // To fetch the next page of records, call `fetchNextPage`.
        // If there are more records, `page` will get called again.
        // If there are no more records, `done` will get called.
        fetchNextPage();
    })

    return data
  },
})

La Lodge : Many thanks ! I will try this as soon as possible. I will tell you if I succeed to proceed the set up
:pray: Thank you

Danny Roosevelt : is there a new Airtable action we should add? To get a record?

Leo : Hello Danny, I have created a ticket to request a new action here: [ACTION] Airtable: Search records #4562