Google Script to edit a record with Webhook Update

With the help of Moe’s instructions in this article, I was able to create a Google script that adds a new line to my Google Sheet each time a record is added to my Tadabase table.

Now I would like to use the Update Record event option in Webhooks to update the corresponding line in my Google Sheets when a record is updated in Tadabase instead of appending a new line with the updated record.

I am using the Tadabase record ID as the first export field, so it should be easy to identify the unique record that needs to be updated. What Google Script commands would I need to use to identify and update the row in the sheet?

I’m not well versed in Google Script, but maybe you could just find the row with the Record ID, delete it, and create a new row with the updated data?

Also, have you considered Integromat?

@tim.young I have looked briefly at Integromat and probably should explore it more.

I came up with a workaround. I found a Google script I used several years ago that takes the last instance of an array for each item in a list. So I can put new records and updated records into one tab (named “Import”) in my Google Sheet, and then use this formula in cell A2 in another tab:

=sort(lastarrayrow(arrayformula(Import!A2:O),2,TRUE))

This assumes I have a header row that I want to skip, and I want columns A thru O.

Here is the script for the LastArrrayRow function:

/**

  • This function returns the last instance of an array for each item in the first column based on the second column.
    */
    function LastArrayRow® {
    var d={};
    for (var i=0;i<r.length;i++) {
    d[r[i][0]]=i
    }
    var a=[];
    for (i in d) {
    a.push(r[d[i]]);
    }
    return a;
    }

Awesome! Sounds like you know your way around Google Scripts!

I’m just good at hunting for code snippets. :face_with_monocle: