If I want a Workflow to only be asynchronously sta...
# ask-stanley-ai
a
If I want a Workflow to only be asynchronously started by a script's task module submitting a triggerWorkflow type of Task, how should I set up the Workflow itself?
c
AI generated answer (using internal Slack threads):
To set up a Workflow that can only be asynchronously started by a script's task module submitting a
triggerWorkflow
type of Task, you should follow these steps: 1. Create your Workflow in NetSuite. Make sure to remove all triggers on the workflow page. This can be done by unchecking both "On Create" and "On View or Update" options. This ensures that the workflow will not be triggered by any other event or action. 2. Set the context of the workflow to ACTION. This means the workflow will only be initiated when it is explicitly called by a script. 3. In your SuiteScript, use the
N/task
module to create a
WorkflowTriggerTask
. This task will be responsible for initiating the workflow. 4. The workflow can be set to run asynchronously using the
N/task
module in your script. This means that the workflow will run in the background, allowing your script to continue executing without waiting for the workflow to complete. 5. If you need to pass data to the workflow, you can do so through a field on the record or through a workflow parameter. Here is a sample code snippet for creating a `WorkflowTriggerTask`:
Copy code
javascript
var workflowTask = task.create({taskType: task.TaskType.WORKFLOW_TRIGGER});
workflowTask.recordType = 'customrecord_my_record'; // replace with your record type
workflowTask.recordId = 123; // replace with your record id
workflowTask.workflowId = 'customworkflow_my_workflow'; // replace with your workflow id
var workflowTaskId = workflowTask.submit();
Remember, workflows run in association with an instance of a record, similar to user events, so you need a unique instance of a record for each async workflow execution. The same workflow cannot be running multiple at the same time on the same record instance. ****** 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.829223633
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826232791
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.825927734
Please provide your feedback on this answer.
Thank you for your feedback
a
Correction: Setting the event type to Action doesn't make this work - it actually works with no Events or Contexts. But other than that, following this got it to work.