Apr 09, 2023 12:10 PM
Hi everyone,
I'm learning airtable scripting and what i want to do is this :
-When a check a checkbox in my table, it run a script which will fetch a webhook. The webhook's url is concatenate with the webhook's url and the recordID.
My script is running well but it concatenate only the recordID from the row 01. Whenever i checked another box from another row...
My question is : is there a solution to concatenate with, my webhook's url, the recordID from the row that i checked the box ?
Here's my script : (a mix of everything I found on the internet)
Solved! Go to Solution.
Apr 09, 2023 01:17 PM
If you only need the record ID of the triggering record, you don't even need to run a query. Just get the record ID from an input variable.
You will need to create the input variable in the left side of the automation script editor. Give it the name recordID and set its value by picking the record ID of the triggering record.
let url="https://hook.eu1.make.com/XXXXXXXXXXXXXXXXXXXXX"
let recordID = input.config()["recordID"]
let request = url + '?ref=' + recordID
await fetch(request);
Apr 09, 2023 12:32 PM - edited Apr 09, 2023 12:32 PM
Hey @Nocode34130!
I need to preemptively write this before you read on. I'm about to run out the door, so I can't type a more in-depth post, but the script you posted will query for every record in your table and return an array of those record objects.
Here's a tweaked version of the script you posted.
const table = base.getTable("Ligne - Matériel");
const records = await table.selectRecordsAsync({ fields: ["recordID"] })
.then(query => query.records);
const sendRequest = async record => {
let url = `https://hook.eu1.make.com/XXXXXXXXXXXXXXXXXXXXX?ref=${record.getCellValueAsString("recordID")}`;
return await fetch(url);
}
records.forEach(async record => await sendRequest(record));
If you want to only send a request for the record that triggered the automation, you need to pass the record ID of the subject record to the script's input variables and then change the invoked method from the table.selectRecordsAsync to table.selectRecordAsync method. It would look something like this:
const { recordId } = input.config();
const table = base.getTable("Ligne - Matériel");
const record = await table.selectRecordAsync(recordId);
const sendRequest = async record => {
let url = `https://hook.eu1.make.com/XXXXXXXXXXXXXXXXXXXXX?ref=${record.getCellValueAsString("recordID")}`;
return await fetch(url);
};
if (record) {
await sendRequest(record);
}
Apr 09, 2023 01:17 PM
If you only need the record ID of the triggering record, you don't even need to run a query. Just get the record ID from an input variable.
You will need to create the input variable in the left side of the automation script editor. Give it the name recordID and set its value by picking the record ID of the triggering record.
let url="https://hook.eu1.make.com/XXXXXXXXXXXXXXXXXXXXX"
let recordID = input.config()["recordID"]
let request = url + '?ref=' + recordID
await fetch(request);
Apr 09, 2023 10:17 PM
A great thanks for both of you ! It's works perfectly :-)))))
Apr 10, 2023 12:21 AM - edited Apr 10, 2023 12:22 AM
For others who are reading this thread and need more detailed instructions on how to set this up, I have written up an entire tutorial on this topic (with screenshots) here.