I have a query that runs correctly when calling qu...
# ask-stanley-ai
m
I have a query that runs correctly when calling query.runSuiteQL but fails when calling task.create. Is there a reason for this?
c
AI generated answer (using internal Slack threads):
The issue you're experiencing might be due to the asynchronous nature of the
task.create
method. When you create a task using
task.create
, it's submitted to a queue and executed asynchronously. This means that the task might not be immediately available when you call
task.checkStatus
. In contrast,
query.runSuiteQL
is a synchronous operation. It executes the query immediately and returns the results. This is why your query works with
query.runSuiteQL
but not with
task.create
. Here's an example of how you might use
task.create
and `task.checkStatus`:
Copy code
javascript
var taskId = task.create({
    taskType: task.TaskType.SUITE_QL,
    query: 'select top 1 id from customer',
    filePath: '/SuiteScripts/MDR/test.csv'
}).submit();

log.debug({ title: 'taskId', details: taskId });

var status = task.checkStatus({
    taskId: taskId
});

log.debug({ title: 'status', details: status });
In this example, a SuiteQL task is created and submitted. The task ID is logged, and then the status of the task is checked and logged. If the task is not immediately available, you might need to wait and check the status again later. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.815553784
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.801491797
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.796299458
Please provide your feedback on this answer.