Hello everyone, thank you in advance for the help. Really appreciated
Script Purpose
When a record is created in first table (with start and end date field), create records with unique dates that go from start to end date in a new table
const tableWithRange =base.getTable("Date range");
const tableWithDays = base.getTable("Days");
console.log(tableWithDays)
let inputConfig = input.config();
const ranges = await tableWithRange.selectRecordsAsync({fields:["Date start","Date end","Employee"]})
var query = await ranges
for (let range of ranges.records){
var fromDate = new Date(range.getCellValue("Date start"));
var toDate = new Date(range.getCellValue("Date end"));
// var employee = new String(range.getCellValue("Employee"));
var outputRecords =[];
var date = new Date()
var i = 1;
do {
var useDate = fromDate
outputRecords.push(
{
fields:{
"Date":new Date(useDate),
"Link to range": [{id: range.id}],
"Record ID" : inputConfig.recordID,
"Employee" : inputConfig.employee,
}
});
console.log(fromDate);
fromDate.setDate(fromDate.getDate() + 1);
i++
}
while (fromDate <= toDate);
console.log(outputRecords);
await tableWithDays.createRecordsAsync(outputRecords)
}
The trigger for this script, is when Status = “Done”
It is successfully creating records, but the problem is when other records have a “Done” status in the first table. The script outputs all of the records that are “Done”. I am wanting to do this so that the script runs only for the trigger record ( inputConfig.recordID), ignoring all other records in the first table. Any advice on how to do this? Thank you, this will be my first script!