Skip to main content

Set Up Automatic Processing

Automating processes within your business can boost efficiency and reduce manual workloads. This page shows you how to set up automated processing using Appsmith Workflows.

Prerequisites

Before you begin, make sure you have:

Configure automated processing

  1. Open your workflow and edit the Main JS Object under JS Objects.

  2. Set up SQL queries or APIs to modify data based on automated processing requirements.

  3. Replace the code in the Main JS Object with custom logic for automatic processing. For instance, the following snippet processes orders based on criteria like order value. If it's below $10, the workflow updates the record, processes a refund, and sends a notification email.

    export default {
    async executeWorkflow(order) {
    if (order && order.order_id) {
    console.log('Processing order: ' + order.order_id);
    // Fetch order details using the provided order ID
    const orderDetails = await getOrderDetails.run({ "order_id": order.order_id });
    // Check if the order meets processing criteria
    if (orderDetails && orderDetails.amount < 10) {
    // Process refund
    await initiateRefund.run({
    "order_id": order.order_id,
    "status": 'Refund Processed'
    });
    // Notify the customer
    await notifyUser.run({
    "user_email": orderDetails.customer_email,
    "user_name": orderDetails.customer_name
    });
    }
    }
    }
    }
  4. Trigger the workflow to process requests automatically. You can do this in one of the following ways:

    • From within an Appsmith app - Create a workflow query with Trigger Workflow as the request type. Pass the required parameters for processing, and bind it to the action from where the triggering happens. For more information on triggering a workflow, see Trigger Workflow from Appsmith App guide.
    • From an external system - Configure the webhook trigger in the workflow. Call the webhook through a POST request and pass the required parameters in the request body. For more information, see Trigger Workflow using Postman.
  5. Click Deploy in the top right to apply your changes.

  6. Execute the workflow when relevant events occur, like a new order request.

Troubleshooting

If you face issues, contact the support team using the chat widget at the bottom right of this page.