Execute code function after ending of workflow
# 🤝help
f
Hello, BotMakers. I am misunderstanding, why executing code operation is starting after ending of whole workflow? I attached the screen of logs.
My code: // Function to retrieve all records from a given table with pagination async function findAllRecords(table) { let allRecords = []; const limit = 30; // Set the number of records to fetch per request let offset = 0; // Initialize offset to start from the first record // Continue fetching records until there are no more to fetch while (true) { const response = await table.findRecords({ limit: limit, offset: offset }); // Check if the response contains records and add them to the allRecords array if (response && response.length > 0) { allRecords = allRecords.concat(response); console.log(
Fetched ${response.length} records. Total fetched: ${allRecords.length}
); offset += limit; // Increase the offset to fetch the next set of records } else { console.log('No more records to fetch or unexpected response:', response); break; // Break the loop if no more records are available or an unexpected response is received } } return allRecords; // Return the array of all fetched records }
// Function to compare records between two tables and find unique records async function compareTables() { try { // Retrieve all records from the two tables const occupancy1Records = await findAllRecords(occupancy1Table); const backdataOccupancy2Records = await findAllRecords(backdataOccupancy2Table); // Log the total number of records retrieved from each table console.log('Total records in occupancy1Table:', occupancy1Records.length); console.log('Total records in backdataOccupancy2Table:', backdataOccupancy2Records.length); // Create a set to store unique 'createdTime' values from the second table const backdataCreatedTimes = new Set(); backdataOccupancy2Records.forEach(record => { if (record['createdTime']) { backdataCreatedTimes.add(record['createdTime']); } }); // Filter records from the first table that don't exist in the second table based on 'createdTime' const uniqueRecords = occupancy1Records.filter(record => record['createdTime'] && !backdataCreatedTimes.has(record['createdTime']) ); // Log the number of unique records found console.log('Number of unique records:', uniqueRecords.length); // Convert the array of unique records to a JSON string const compare = JSON.stringify(uniqueRecords); if (uniqueRecords.length > 0) { console.log('Unique records:', compare); return compare; // Return the JSON string of unique records for further use } else { console.log('No unique records found.'); return null; // Return null if no unique records are found } } catch (error) { // Log any errors encountered during the comparison console.error("Error comparing tables: ", error.message); return null; } }
// Call the compareTables function and handle the results compareTables().then(compare => { if (compare) { // Log and handle the unique records if the comparison is successful console.log('Here are the unique records:', compare); // Place for further actions with the unique records } });
May be someone can help me, please 🙏
2 Views