ZOHO Flow - Command & Scripts

ZOHO Flow - Command & Scripts

ZOHO Flow - Command & Scripts

The “Commands & Scripts - Execute Command” feature in Zoho Flow allows you to execute custom scripts or commands within your workflow. It is particularly useful for handling advanced logic, transforming data, or performing operations that are not directly supported by the standard Flow actions.

Here’s a detailed walk-through of the Execute Command feature and its settings:


Purpose of “Execute Command”

  • To transform data: Apply custom logic or calculations to manipulate data before passing it to the next step.
  • To create conditional workflows: Execute custom logic to decide what actions to perform based on specific criteria.
  • To simplify workflows: Replace multiple Flow actions with a single custom script.
  • To handle API requests: Make API calls to third-party services or process data from external systems.

Key Components of the Setup

  1. Name:

    • Purpose: Specify a name for the command.
    • Usage: Helps identify the command within your Flow.
    • Example: “Calculate Total Amount” or “Format Customer Data”.
  2. Input Fields:

    • Purpose: Define the data that the script will use as input.
    • Settings:
      • Field Name: A name for the input variable (e.g., price, quantity).
      • Data Type: Choose the type of data (Number, Text, Boolean, Date-Time, or Array).
    • Example: For a calculation, you might define:
      • price (Number)
      • quantity (Number)
  3. Command Script:

    • Purpose: Write the script to process the input fields.
    • Supported Language: Deluge (Zoho’s scripting language).
    • Features:
      • Use predefined variables (input fields) for processing.
      • Perform calculations, transformations, or logic branching.
      • Output processed data.
    • Example Script:
      total = input.price * input.quantity;
      return {"total_amount": total};
      
    • Explanation:
      • input.price and input.quantity are the input fields.
      • The script calculates the total amount and returns it as a total_amount variable.
  4. Output Fields:

    • Purpose: Define the data returned by the script, which can be used in subsequent Flow steps.
    • Settings:
      • Field Name: A name for the output variable (e.g., total_amount).
      • Data Type: The type of the returned data (Number, Text, Boolean, etc.).
    • Example:
      • Field Name: total_amount
      • Data Type: Number

Step-by-Step Setup Example

Scenario:

You want to calculate the total amount for an order (price × quantity) and pass the result to another step.

Steps:

  1. Add the “Execute Command” Action:

    • In your Flow, add the Execute Command action.
  2. Set Up Input Fields:

    • Add two input fields:
      • price (Number)
      • quantity (Number)
  3. Write the Script:

    total = input.price * input.quantity;
    return {"total_amount": total};
    
  4. Define Output Fields:

    • Add an output field:
      • total_amount (Number)
  5. Use the Output:

    • Use the total_amount output field in subsequent steps (e.g., send it in an email or update a database).

Advanced Examples

Example 1: Conditional Logic

  • Scenario: You want to check if an order qualifies for a discount.

  • Script:

    if (input.order_total > 1000)
    {
        return {"discount_eligible": true};
    }
    else
    {
        return {"discount_eligible": false};
    }
    
  • Output Field:

    • discount_eligible (Boolean)

Example 2: API Request

  • Scenario: Make an API call to fetch exchange rates.

  • Script:

    url = "https://api.exchangerate-api.com/v4/latest/USD";
    response = getUrl(url);
    data = response.toJSONList();
    return {"exchange_rate": data.get("rates").get(input.currency)};
    
  • Input Field:

    • currency (Text)
  • Output Field:

    • exchange_rate (Number)

Testing the Command

  • After defining the input fields, script, and output fields:
    1. Click on the Test & Save button.
    2. Provide sample input values to test the script.
    3. Verify that the output fields return the expected results.

Best Practices

  1. Use Descriptive Field Names:
    • Clearly name your input and output fields for better readability.
  2. Validate Input:
    • Add validation logic to handle unexpected or missing input.
    • Example:
      if (input.price == null || input.quantity == null)
      {
          return {"error": "Invalid input"};
      }
      
  3. Document Your Scripts:
    • Add comments in your script for complex logic.

When to Use “Execute Command”

  • When standard Flow actions do not support your required logic.
  • When integrating external APIs or systems.
  • For data transformation tasks like calculations, string manipulations, or custom branching logic.

Further Resources

This approach gives you complete control over your data and workflows, enabling custom logic and integrations.

    • Related Articles

    • ZOHO FLOW IN THE BUSINESS LANDSCAPE

      ZOHO FLOW IN THE BUSINESS LANDSCAPE Zoho Flow is a powerful integration and automation tool within the Zoho ecosystem. It allows businesses to connect multiple applications, automate workflows, and enhance productivity without requiring extensive ...
    • Time and Resource Management - Agile Project Management, Service Desk Tickets or Projects

      If you find the overwhelm of all the available systems that all seem to do much of the same thing, leaving you with a feeling of inadequacy, and unable to face the technological future, read this to figure out which tools all do roughly the same ...
    • How to send a comment to the Customer or Ticket Creator

      1. Sending a Comment to the Customer or Ticket Creator Zoho Desk allows you to add comments to tickets, and you can choose whether to make these comments public (visible to the customer) or private (visible only to agents). To send a comment to the ...