# Workflow Action: Send to Orderful (Custom)

## Overview

The **Send to Orderful** workflow action allows you to automatically send already-generated outbound EDI transactions to Orderful from Orderful Transaction records using NetSuite workflows. This provides a programmatic alternative to the manual "Send to Orderful" button.

## Use Cases

Use this workflow action to:

* Automatically send custom or non-standard document types to Orderful when certain conditions are met
* Trigger sending as part of a larger business process workflow
* Eliminate manual steps for sending pre-generated EDI transactions
* Ensure transactions are dispatched to Orderful immediately upon meeting specific criteria

## Supported Transaction Types

This workflow action works with outbound Orderful Transaction records that have **custom or non-standard document types**. For standard document types (810, 855, 856, 880, 940, and simplified variants), use the [Generate and Send workflow action](workflow-action-generate-and-send.md) instead.

## Prerequisites

* The workflow action script must be deployed to your NetSuite account
* Script ID: `customscript_orderful_send_orderful_wa`
* Deployment ID: `customdeploy_orderful_send_orderful_wa`
* The script must be in RELEASED status

## Setup Instructions

### 1. Deploy the Script

The workflow action script should be automatically deployed when the Orderful bundle is installed. Verify deployment:

1. Navigate to **Customization > Scripting > Scripts**
2. Search for "Orderful | Send to Orderful WA"
3. Verify the script status is **Released**
4. Check that the deployment is **Deployed**

### 2. Create or Edit a Workflow

To add the Send to Orderful action to a workflow:

1. Navigate to **Customization > Workflow > Workflows**
2. Create a new workflow or edit an existing one
3. Set the **Record Type** to **Orderful Transaction**
4. Add a workflow state where you want the action to execute

### 3. Add the Workflow Action

Within your workflow state:

1. Click **Add Action** under the appropriate trigger type (e.g., After Field Edit, On Entry, etc.)
2. Select **Execute Script** as the action type
3. Configure the action:
   * **Script**: Select "Orderful | Send to Orderful WA"
   * **Deployment**: Select "Orderful | Send to Orderful WA"
4. Optionally add conditions to control when the action executes

### 4. Set Workflow Conditions (Optional)

To ensure the action only runs for appropriate transactions, add conditions such as:

* **Direction** = Outbound
* **Document Type** is NOT one of the standard types (810, 855, 856, etc.)
* **Status** ≠ Success (to avoid reprocessing)
* **Message** is NOT empty (transaction already generated)
* Any custom field criteria specific to your business logic

## Example Workflow Configuration

### Auto-Send Custom Document Types

This example automatically sends custom document type transactions when they're ready:

**Workflow Settings:**

* **Record Type:** Orderful Transaction
* **Trigger:** After Field Edit
* **Init On Create:** True

**Workflow State:**

* **Name:** Auto-Send Custom Documents
* **Trigger Type:** On Entry

**Workflow Action:**

* **Type:** Execute Script
* **Script:** Orderful | Send to Orderful WA
* **Conditions:**
  * Direction = Outbound
  * Custom Flag Field = True (indicating transaction is ready)
  * Message is NOT empty

## What the Action Does

When executed, the workflow action:

1. Loads the Orderful Transaction record
2. Validates the transaction exists
3. Sends the transaction to Orderful via API (calls `createTransactionInOrderful`)
4. Updates the transaction status and logs the result

This is the same functionality as clicking the "Send to Orderful" button manually.

## Error Handling

If the workflow action encounters an error:

* The error is logged to the script execution log (Error level)
* The error is written to the Orderful Transaction record
* The workflow will halt or continue based on your workflow configuration
* Check **Customization > Scripting > Script Execution Log** for detailed error information

## Troubleshooting

### Action Not Executing

* Verify the script deployment is **Released** and **Deployed**
* Check workflow conditions are being met
* Review the workflow execution log
* Ensure the user role has permission to execute the script

### Transaction Not Being Sent

* Verify the transaction has a message/payload already generated
* Check the Orderful Transaction record for error messages
* Review the script execution log for detailed error information
* Ensure API credentials are configured correctly

### Duplicate Transactions

* Add a condition to check transaction status before executing
* Ensure workflow doesn't trigger multiple times for the same record
* Use the transaction's existing flags to prevent reprocessing

## Best Practices

1. **Add Status Checks:** Always check that the transaction hasn't already been successfully sent
2. **Validate Message Exists:** Ensure the transaction has a message/payload before sending
3. **Use Specific Conditions:** Only trigger on the appropriate document types and states
4. **Test in Sandbox:** Thoroughly test your workflow in a sandbox environment before deploying to production
5. **Monitor Execution:** Regularly review script execution logs during initial rollout

## Differences from Generate and Send

| Feature                            | Send to Orderful WA            | Generate and Send WA        |
| ---------------------------------- | ------------------------------ | --------------------------- |
| **Purpose**                        | Send existing message          | Generate + Send             |
| **Document Types**                 | Custom/non-standard            | Standard EDI types          |
| **Requires Pre-Generated Message** | Yes                            | No                          |
| **Use Case**                       | Already-generated transactions | Generate from source record |

<br />