Dec 03, 2022 12:21 PM
I have a fairly complex set-up with Airtable automation and Integromat automation that does a whole bunch of stuff very nicely. I'll attempt a simple description of one part of it that is relevant to my request...
People can use a form to "watch" for changes in a record. Their email address is added as a multiple-select option to that record when they submit the form. The automation I've set up sends them an email when that record changes.
This all works fine but now I want to allow them to cancel this alert and I'm a bit stumped. My thinking is that they can use a second form which references the record and their email address and when it's submitted the automation will look up the record and remove the multiple-select option that matches the email address if it exists.
I just don't know how to do this. I'm assuming a script will be required and I'm not familiar with scripting myself.
Help? 😅
Dec 03, 2022 07:43 PM
Hi @Stu_Smith !
If you are already using Integromat, would something like this work for you?
Use some trigger like e.g. webhook to trigger search for the reference record and use `remove` function in next step to take out the email from the array of Multiselect.
If you would like to do it with code. You could use the filter function to remove that one multiselect option that is equal to email that needs to be removed.
Let me know if that helps!
Dec 03, 2022 07:47 PM
here is the code, apologies for plain text - it looks like the new community is not allowing me to embed code block (even from the toolbar...)
let table = base.getTable("Rooms");
let field = table.getField("Multiselect");
let emailToRemove = "email1"
let recordToUpdate ="recsjobMMpxlE7saG"
// Load all of the records in the table
let result = await table.selectRecordsAsync({fields: [field]});
let record = result.getRecord(recordToUpdate)
let updadatedRecord = await table.updateRecordAsync(recordToUpdate,{
"Multiselect": record.getCellValue("Multiselect").filter(option=>option.name!==emailToRemove)
})
Dec 04, 2022 12:04 AM
Thanks! I've tried to implement this, swapping out some of the variables to match mine but I'm getting the error that it can't find the record. Record ID is correct so I think I've gone wrong at the first line... what should be where you have "Rooms"?
Dec 04, 2022 01:18 AM
I tested it on a datase I was using, so in my case the table name was "Rooms". "Multiselect" is a name of column that is of a multiselect type and it has multiple emails as options.
The recordToUpdate is the ID of the record, from which one of the emails is supposed to be removed.
Let me know if this is making sense?
Dec 04, 2022 01:37 AM
Yup. Makes sense. So I've changed it to the following using the table ID, column name from that table, and the two variable pulled from the form (see screengrab). The script input values are correct for the record ID and email address. I get this error: "Error: No record matching "product_record" found in query
at main on line 9"
Dec 04, 2022 01:37 AM
Dec 04, 2022 01:39 AM
Dec 04, 2022 01:48 AM
OK I see it now!
Delete this part:
Dec 04, 2022 01:49 AM
And replace it with
Dec 04, 2022 01:53 AM
Oooh. Looks like it got a bit further but now we have this error:
ERROR
TypeError: Invalid arguments passed to recordQueryResult.getRecord(recordId):
• recordId should be a string, not an array
at main on line 11
Dec 04, 2022 01:53 AM
This is for me the fastest way to access the input variables.
I kept your names there, but actually you could also shorten it by renaming the input variables to recordToUpdate and emailToRemove and only us this:
Dec 04, 2022 01:56 AM
True,
Your product_record is a linked field - there could be multiple products linked, so it is array of recordIs if you are sure it is only 1 , you could do this:
let recordToUpdate = product_record[0]
This will pick the first link from the array of records.
Dec 04, 2022 02:02 AM
Amazing! That worked! Thanks so much... no way I would've worked that out myself. 😁
The form will autocomplete via a link in the alert emails that go out with the record ID and email address. I'l;l limit it to single select so people don't try to add more.
Onto the next stage of testing.
Thanks again. ❤️
Dec 04, 2022 02:05 AM
🤘🚀Cool!