Getting an error when storing data on a javascript query

Hi All,

So I've got a Javascript query (see below) which is trying to store a variable selectedFields to SaveLastRun.data however, I am getting an undefined stored on data when I run the script.

Checked the console.log and it is showing the correct WorkID number and data length, but I am getting an additional error (see below).

Javascript query
// Assuming your table component is named "tableorders"
const table = TableOrders;

// Get the last row index
const lastRowIndex = table.data.length - 1;

// Select the last row with an empty options object
table.selectRow(lastRowIndex, {})

// Replace "fieldName" with the name of the field you want to select
const selectedField = table.data[lastRowIndex].WorkOrderID;
SaveLastRun.data = selectedField;

console.log("Selected Fields: " + selectedField);
console.log("Data Length: " + table.data.length);

Error:

Error:Options must be an object.

in TableWorkOrders.selectRow()

:arrow_forward:in SaveLastRun2.trigger()(SaveLastRun2)

  1. additionalScope: {}

triggeredById: ""environment: "production"

Cheers,

What does the trigger code look like and are you using additionalScope?

Hi Scott,

Thanks for the reply. We've managed to fix the error and got the output we wanted.

It was the way we setup the component and variable that we missed.

1 Like