I would like to create a script that checks if my employee has already taken an advance on the same day. If it has already been taken, the new record should be deleted. I do this in the form. How can I get the current record ID from the form and delete it or add it if it was the first time.
let table = base.getTable("Zaliczki"); // Zamień "Nazwa_Tabeli" na nazwę swojej tabeli
// Pobierz dzisiejszą datę w formacie ISO
let today = new Date().toISOString().split('T')a0];
// Pobierz rekordy, które mają dzisiejszą datę
let existingRecords = await table.selectRecordsAsync({
filterByFormula: `IS_SAME({Data}, DATESTR(TODAY()), 'day')`
});
// Sprawdź, czy istnieje już rekord z dzisiejszą datą
if (existingRecords.records.length > 0) {
// Jeśli istnieje, usuń nowo dodany rekord
let newRecordId = input.config().recordId;
if (newRecordId) {
await table.deleteRecordAsync(newRecordId);
output.set('message', 'Rekord z dzisiejszą datą już istnieje. Nowy wpis został usunięty.');
} else {
output.set('message', 'Nie udało się uzyskać ID nowego rekordu.');
}
} else {
output.set('message', 'Formularz wypełniony pomyślnie.');
}
