Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Query.run() is not a function

Issue

I am having trouble using a JavaScript function to provide data for my page widget. When I use a SQL query, it works fine, but when I use my function, I get an error saying that the function is not recognized. I have tried removing the function call and it works, but I need to be able to use my function for added logic. Can someone please help me with this issue?

Resolution

The issue described involves using a JavaScript object to provide data for a page widget instead of using an SQL query. However, when the JS function is used in the context of table data, there is an error indicating that select_query.run is not a function.

To resolve this issue, it is recommended to use {{JSObject1.load.data}} in the TableData property. This syntax allows the response of the async function to be used in a sync field. An example code snippet that demonstrates this solution is provided below:

import { select_query } from "./data.js";

export default {
load: async () => {
await select_query.run();
return select_query.data;
}
}

// Use {{JSObject1.load.data}} in the TableData property

Note that the load function is marked as async and uses await to wait for the data to be fetched before returning it. This may help ensure that the data is properly loaded before it is used in the table.