Help

Script only works when base has no records

Topic Labels: Extensions
Solved
Jump to Solution
1543 2
cancel
Showing results for 
Search instead for 
Did you mean: 
Josh_Colina
6 - Interface Innovator
6 - Interface Innovator

Hello!

I am wondering if anybody can help me troubleshoot why a script stops working when there are records in my base?

The script in question is the “Creating Projects/Tasks From Templates” script (which I found here). I am also including share links to 2 test bases for reference on my problem (those are located here and here). The Sandbox for Question (1) table is copied from my company’s Workspace, and includes confidential information that I’ve renamed to “Redact” - very sorry if this makes addressing this issue more complicated or confusing!

I use this script to batch create tasks (in the Tasks table) from a template (defined in the Asset Templates table and Task Templates table) that are parented to a specific asset. I recently started to encounter this error when trying to run the script:

> TypeError: Cannot read properties of null (reading '0') at main on line 87

For context, this is line 87 in the script:

    let p_id = r.getCellValue(project_template_link_field_name)[0].id;

However, when I made a copy of my base to try to figure out what happened and cleared out all the records in the Tasks, Assets, Client Projects, People, Utilization, Products, and Timesheets tables, the script started working again when tested. I’m not familiar with scripting, so I’m not sure why this would have happened. I also would note that I started encountering this issue after adding the Utilization table and did not have this issue before - however, this table and its data aren’t involved (as far I can tell) in the script.

As you can see in the bases I’ve linked, the script will not work in Sandbox for Question (1) (which is populated with records) but will if tested in Sandbox for Question (2) (which is identical in architecture but has been emptied of records).

Could somebody advise, or has anyone encountered similar (especially with this script)?

Thank you very much!

1 Solution

Accepted Solutions
TheTimeSavingCo
18 - Pluto
18 - Pluto

Hi @Josh_Colina, if it helps it looks like your New Assets view contains records that have empty Asset Type values, which is causing that error message you’re seeing

Once you modify your filter to only display records where the Asset Type field isn’t empty your code runs fine

See Solution in Thread

2 Replies 2
TheTimeSavingCo
18 - Pluto
18 - Pluto

Hi @Josh_Colina, if it helps it looks like your New Assets view contains records that have empty Asset Type values, which is causing that error message you’re seeing

Once you modify your filter to only display records where the Asset Type field isn’t empty your code runs fine

Hi @Adam_TheTimeSavingCo! This is a big case of :fried_egg: egg on my face - this is a great spot, thank you very much!