Jul 24, 2024 07:20 AM
I have a database with two tables “gifts” and “status”. I'd like to use a button to update the status automatically via a script.
I searched the documentation and the forum, but I couldn't find any solution to adapt the script to my problem. Here's the code I've already added, and the options I've explored.
This is my code :
// Récupère la table Cadeaux
let tableCadeaux = base.getTable("🎁 Cadeaux");
console.log(tableCadeaux);
//Récupère le champo statuts de la table Cadeaux
let statut = tableCadeaux.getField("✅ Statuts");
console.log(statut);
// Récupère le record.id de la table Cadeaux
let queryResult = await tableCadeaux.selectRecordsAsync({fields: []});
let record = queryResult.records[0];
console.log(record.id);
// Récupère la table Statuts
let tableStatuts = base.getTable("✅ Statuts");
console.log(tableStatuts);
let newRecordIdToLink = '🎁 Réservé';
tableCadeaux.updateRecordAsync(record, {
"✅ Statuts": [
record.getCellValue("✅ Statuts"),
{ id: newRecordIdToLink }
]
})
and the documentation I looked at : multipleRecordLinks
https://airtable.com/developers/scripting/api/cell_values#multiple-record-links
I'm getting an error that I don't understand, maybe you have an answer or the logic that I haven't understood yet.
Thank you in advance
Jul 24, 2024 07:24 AM
Could you provide screenshots of the relevant fields and explain what you want the script to do?
Jul 24, 2024 11:56 AM
Hello, thank you for your time TheTimeSavingCo.
The idea is simply to be able to change the status of a record when the button is clicked from an interface, because here the status is a “Link to Another record” and not a select.
I need to change the record I click on from an A status to a B status defined in the script.
But I'd also like to understand what I'm doing, and at the end of the script I can't see how to do it.
Jul 24, 2024 06:33 PM
Ah thanks for the details! If you could provide a screenshot of the specific fields involved I could try to help!
Jul 25, 2024 04:42 AM - edited Jul 25, 2024 08:48 AM
Yes of course :
I only want to update the field ” ✅ Statuts” when I click on the button (which contains the script) in the table "🎁 Cadeaux"
Thanks a lot
Jul 25, 2024 07:27 PM
Thanks! Here's some code that I got working:
// Récupère la table Cadeaux
let tableCadeaux = base.getTable("🎁 Cadeaux");
console.log(tableCadeaux);
//Récupère le champo statuts de la table Cadeaux
let statut = tableCadeaux.getField("✅ Statuts");
console.log(statut);
// Récupère le record.id de la table Cadeaux
let queryResult = await tableCadeaux.selectRecordsAsync();
let record = queryResult.records[0];
console.log(record.id);
// Récupère la table Statuts
let tableStatuts = base.getTable("✅ Statuts");
console.log(tableStatuts);
let newRecordIdToLink = 'recz4E29hpLQtrkvy';
tableCadeaux.updateRecordAsync(record, {
"✅ Statuts": [
...record.getCellValue("✅ Statuts") || [],
{ id: newRecordIdToLink }
]
})
I changed `let newRecordIdToLink = '🎁 Réservé';` to use a record ID as that's what the linked field requires, and I also updated the code so that it could append the record to any existing values in the field