Help

Junction Table Script Exceeded Execution Time Limit

Topic Labels: Automations
488 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Dominic
6 - Interface Innovator
6 - Interface Innovator

Hi,

I have written a script that is triggered within an automation that essentially builds out a junction table. The issue is that it frequently fails with the error "Script exceeded execution time limit of 30 seconds". Does anyone know of ways I could edit this so that it will more likely run within the 30sec time limit?

Many thanks in advance!

 

let classesTable = base.getTable('Classes');
let clientsTable = base.getTable('Clients');
let attendanceTable = base.getTable('Attendance');
let attendanceQuery = await attendanceTable.selectRecordsAsync();

// Get the record ID from the automation input
let triggeringRecordId = input.config().recordId;

// Retrieve all the records in the Classes table
let classesQuery = await classesTable.selectRecordsAsync();
let classesRecords = classesQuery.records;

// Find the triggering record using the provided ID
let classesRecord = classesRecords.find(record => record.id === triggeringRecordId);
let classDate = classesRecord.getCellValue('Class');
let scenesToConduct = classesRecord.getCellValue('Scenes to Conduct');
let clientsInRoster = classesRecord.getCellValue('Clients in Roster');

// If any required field is empty, return and quit the script
if (!classDate || !scenesToConduct || !clientsInRoster) {
return;
}

// Loop through all scenes and clients to generate unique combinations
for (let scene of scenesToConduct) {
for (let clientId of clientsInRoster) {

// Check if the combination already exists in the Attendance table
let existingRecord = attendanceQuery.records.find(record =>
record.getCellValue('Class')[0].id === classesRecord.id &&
record.getCellValue('Scene').id === scene.id &&
record.getCellValue('Client').id === clientId
);

// If the combination doesn't exist, create a new record in the Attendance table
if (!existingRecord) {
await attendanceTable.createRecordAsync({
'Class': [{id: classesRecord.id}],
'Scene': [{id: scene.id}],
'Client': [{id: clientId}],
});
}
}
}
0 Replies 0