Logo Logo Help centre
Search
Sign in
  • Contact us
    support@upsales.com +468 505 806 01 Share your screen
    Upsales Nordic AB Sveavägen 21 111 34 Stockholm
  1. Upsales Help Centre
  2. Upsales AI
  3. AI overview

How to Create an Order Validation Agent

Automatically validate orders before they're saved by checking business rules like maximum discount percentages. This guide walks you through creating an AI Agent that prevents orders with excessive discounts from being saved.


Table of Contents

  1. Overview
  2. Prerequisites
  3. Step 1: Access AI Agents
  4. Step 2: Create a New Agent
  5. Step 3: Add Conditional Logic
  6. Step 4: Configure Validation Responses
  7. Step 5: Save and Activate
  8. Testing Your Agent
  9. Troubleshooting

Overview

AI Agents allow you to automate workflows in Upsales. In this tutorial, you'll create an agent that:

  • Triggers when an opportunity or order is created or updated
  • Checks if the discount percentage exceeds a maximum threshold (20%)
  • Blocks the save operation if the discount is too high
  • Allows the save if the discount is acceptable

Use case: Ensure sales representatives cannot save orders with discounts greater than 20% without approval.


Prerequisites

Before you begin, ensure you have:

  • Access to Upsales with administrator permissions
  • The AI Agents feature enabled for your account

Step 1: Access AI Agents

  1. Log in to power.upsales.com
  2. In the left sidebar, click on AI Agents

You'll see the AI Agents overview page where you can manage all your agents.


Step 2: Create a New Agent

  1. Click Create agent in the top right corner
  2. Select Upsales Validation Trigger from the trigger options

  1. Double-click the trigger node to open its settings
  2. Under What, select Order from the dropdown

  1. Click outside the settings to close them

You'll now see your trigger node in the Agent editor.

Note: The user will wait for the agent to finish before the order saves.


Step 3: Add Conditional Logic

Now we'll add an If node to check the discount percentage.

  1. Click the + button next to your trigger node
  2. In the nodes panel, select Flow

  1. Click on If to add it to your workflow

  2. Configure the If node:

    • Click on the If node to open its settings
    • Set the condition as follows:

To calculate the discount percentage, we need to compare the total list price with the total sales price across all order rows. Copy and paste this expression exactly into the left value field:

Field Value
Left value {{ (1 - $json.data.orderRow.map(row => row.price).sum() / $json.data.orderRow.map(row => row.listPrice).sum()) * 100 }}
Operator is greater than
Right value 20

Tip: You don't need to understand this expression — just copy and paste it exactly as shown. It calculates the discount percentage from the order rows.

  1. Click outside the settings to close them

The If node now has two outputs:

  • true — when the discount is too high (greater than 20%)
  • false — when the discount is acceptable (20% or less)


Step 4: Configure Validation Responses

You need to add a Respond to Webhook node for each output to tell Upsales whether to allow or block the save.

4a. Block the Save (when discount is too high)

  1. Click the + button next to the true output on the If node
  2. Search for "Respond to Webhook" and select it
  3. Configure the node:
    • Set Respond With to JSON
    • Enter the following in the Response Body:
{
  "validationPassed": false,
  "errorMessage": "Discount exceeds maximum allowed (20%)"
}

  1. Click outside the settings to close them

4b. Allow the Save (when discount is acceptable)

  1. Click the + button next to the false output on the If node
  2. Search for "Respond to Webhook" and select it
  3. Configure the node:
    • Set Respond With to JSON
    • Enter the following in the Response Body:
{
  "validationPassed": true
}

  1. Click outside the settings to close them

Step 5: Save and Activate

Your complete workflow should look like this:

  1. Click the Save button in the top right corner
  2. Toggle the Inactive switch to Active to enable the agent

Important: Once activated, this agent will run for all users in your account. Make sure your validation rules are correct before enabling it.


Testing Your Agent

To test your validation agent:

  1. Create a new order in Upsales

  2. Add products and set a discount greater than 20%

  3. Try to save the order

  4. You should see an error message: "Discount exceeds maximum allowed (20%)"

  5. Now change the discount to 20% or less

  6. Save the order

  7. The order should save successfully


Troubleshooting

The agent doesn't trigger

  • Ensure the agent is set to Active
  • Verify you selected Order under What in the trigger settings

The validation always fails or always passes

  • Double-check that you copied the expression exactly as shown
  • Verify the operator is set to "is greater than"
  • Ensure the right value is 20 (not in quotation marks)

Error messages don't appear

  • Make sure errorMessage is included in your validation failed response
  • Check that validationPassed is set to false without quotation marks around the word false

JSON Response Reference

Block the save (validation failed)

{
  "validationPassed": false,
  "errorMessage": "Your error message here"
}

Allow the save (validation passed)

{
  "validationPassed": true
}

Next Steps

  • Create validation agents for other types (Subscriptions, Companies)
  • Add more complex validation rules with multiple conditions
  • Integrate with external systems for advanced validation logic

Need help? Contact Upsales support if you have questions about AI Agents.

Was this article helpful?
Have more questions? Submit a request
Return to top

Articles in this section

  • Upsales AI overview
  • Upsales MCP Connector: How to Connect Your CRM to AI Assistants
  • How to Create an Order Validation Agent
  • Så analyserar Upsales dina affärer
  • How Upsales Assesses Your Deals
  • The E40 performance metric
  • AI news analysis
  • AI sales efficiency
  • Upsales industry intelligence
  • Business relation signals

Can't find what you're looking for?

Contact Upsales Customer Success:

Chat Call Email
Help Center API Status Visit upsales.com
support@upsales.com +468 505 806 01 Share your screen