Help

Automation Script sending different data than Script App

Topic Labels: Automations Data
497 0
cancel
Showing results for 
Search instead for 
Did you mean: 
r0anne0h
5 - Automation Enthusiast
5 - Automation Enthusiast

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 NumberTask NameSubtask Name
12345My Task 
  My Subtask
  My Subtask

Ultimate Goal:

Task NumberTask NameAssociated Task Number for SubtasksSubtask Name
12345My 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?

0 Replies 0