Hello!
I'm not sure how to approach this issue, as I'm fairly new to scripting. I am creating a script to copy a cell value from the last filled cell in a column to a cell in a new column if the value in the first column is blank. The use case here is to associate subtasks with a main task. To note - this is based on external tasks requests, and I do not have the option to reformat the way that the requests come in.
Here's an example of what I mean:
Current Setup:
Task Number | Task Name | Subtask Name |
12345 | My Task | |
| | My Subtask |
| | My Subtask |
Ultimate Goal:
Task Number | Task Name | Associated Task Number for Subtasks | Subtask Name |
12345 | My Task | | |
| | 12345 | My Subtask |
| | 12345 | My Subtask |
To the script! This script works perfectly in the Script App on my table, but when I use the same script in Automations, seemingly random numbers are filled in for the Task ID. Here is the code:
let mytable = base.getTable('Task Table');
let query = await mytable.selectRecordsAsync();
let previous = "";
for (let record of query.records) {
let current = record.getCellValue('Task Number');
if (current) {
previous = current;
} else {
await mytable.updateRecordAsync(record, {'Associated Task Number for Subtasks': previous})
}
}
Any ideas where I'm going wrong with the automation?