Manual approvals often cause delays, errors, and inconsistent decisions. Automation solves this by applying rules instantly and consistently, giving your business faster execution and stronger compliance.

Instead of hard-coding logic, approval rules can be managed dynamically. With Drools, a Business Rule Management System (BRMS), you can define rules that automatically route orders to the right approval level—streamlining workflows and reducing manual effort.

Why use Drools for Approval Logic

If you need some intro why we need Drools, you can read here:

Implementation Steps

This tutorial assume you have Drools installation, if you don’t have, you can read how to install Drools using Docker here:

To demonstrate this, we’ll walk through a simple setup:

  1. Define a Data Object that represents a SalesOrder.
  2. Create approval rules in Drools that check order amounts and assign the right approver.
  3. Deploy and test the rules to see automated approvals in action.

Define Data Object

Using business central, on your project, add new asset “Data Object”:

add field:

this the java code for the SalesOrder data object – generated by Business Central:

package com.myspace.hello_rules;

/**
 * This class was automatically generated by the data modeler tool.
 */

public class SalesOrder implements java.io.Serializable {

	static final long serialVersionUID = 1L;

	@org.kie.api.definition.type.Label(value = "Amount")
	private java.lang.Double amount;
	@org.kie.api.definition.type.Label(value = "Region")
	private java.lang.String region;
	@org.kie.api.definition.type.Label(value = "Project Code")
	private java.lang.String projectCode;
	@org.kie.api.definition.type.Label(value = "Customer")
	private java.lang.String customer;
	@org.kie.api.definition.type.Label(value = "Approval Status")
	private java.lang.String approvalStatus;
	@org.kie.api.definition.type.Label(value = "Approver")
	private java.lang.String approver;

	public SalesOrder() {
	}

	public java.lang.Double getAmount() {
		return this.amount;
	}

	public void setAmount(java.lang.Double amount) {
		this.amount = amount;
	}

	public java.lang.String getRegion() {
		return this.region;
	}

	public void setRegion(java.lang.String region) {
		this.region = region;
	}

	public java.lang.String getProjectCode() {
		return this.projectCode;
	}

	public void setProjectCode(java.lang.String projectCode) {
		this.projectCode = projectCode;
	}

	public java.lang.String getCustomer() {
		return this.customer;
	}

	public void setCustomer(java.lang.String customer) {
		this.customer = customer;
	}

	public java.lang.String getApprovalStatus() {
		return this.approvalStatus;
	}

	public void setApprovalStatus(java.lang.String approvalStatus) {
		this.approvalStatus = approvalStatus;
	}

	public java.lang.String getApprover() {
		return this.approver;
	}

	public void setApprover(java.lang.String approver) {
		this.approver = approver;
	}

	public SalesOrder(java.lang.Double amount, java.lang.String region,
			java.lang.String projectCode, java.lang.String customer,
			java.lang.String approvalStatus, java.lang.String approver) {
		this.amount = amount;
		this.region = region;
		this.projectCode = projectCode;
		this.customer = customer;
		this.approvalStatus = approvalStatus;
		this.approver = approver;
	}

}

Define rule

Create new rule: approval-rules.drl

package com.myspace.hello_rules;

import com.myspace.hello_rules.SalesOrder;

rule "Auto-approve under 10k"
when
    $order: SalesOrder(amount < 10000)
then
    $order.setApprovalStatus("APPROVED");
    $order.setApprover("SYSTEM");
end

rule "Manager approval 10k-50k"
when
    $order: SalesOrder(amount >= 10000 && amount < 50000)
then
    $order.setApprovalStatus("PENDING_MANAGER");
    $order.setApprover("MANAGER");
end

rule "Director approval 50k-200k"
when
    $order: SalesOrder(amount >= 50000 && amount < 200000)
then
    $order.setApprovalStatus("PENDING_DIRECTOR");
    $order.setApprover("DIRECTOR");
end

rule "C-level approval above 200k"
when
    $order: SalesOrder(amount >= 200000)
then
    $order.setApprovalStatus("PENDING_C_LEVEL");
    $order.setApprover("C_LEVEL");
end

rule "Special region/project code"
when
    $order: SalesOrder(region == "APAC" || projectCode == "SPECIAL")
then
    $order.setApprovalStatus("REQUIRES_ADDITIONAL_REVIEW");
end

rule "Flagged vendor"
when
    $order: SalesOrder(customer == "CUSTOMER_XYZ")
then
    $order.setApprovalStatus("MANDATORY_SECONDARY_APPROVAL");
end

Deploy and test

TL;DR

  1. Add the DRL file to your Drools project in Business Central.
  2. Build and deploy the project.
  3. Use the KIE server REST API to insert a SalesOrder fact and fire rules.
  4. call KIE server API to fire all rules.

Increase version (optional)

Go to your project, open tab “Settings”, scroll down find “Version”, increase:

Build and deploy the project, then delete the old version, you will see 1 version, and its 1.0.1:

Call KIE-Server API to fire all rules:

reference: https://docs.drools.org/6.5.0.Final/drools-docs/html/ch22.html#d0e25288

using postman, create a “POST” request with URL:

http://localhost:8180/kie-server/services/rest/server/containers/instances/hello-rules_1.0.1-SNAPSHOT

Authorization set to basic with username=admin and password=admin

Header add new

Content-Type=application/json

Body use raw (JSON):

{
  "commands": [
    {
      "insert": {
        "object": {
          "com.myspace.hello_rules.SalesOrder": {
            "amount": 500,
            "region": "EU",
            "projectCode": "P999",
            "customer": "CUSTOMER_ABC"
          }
        },
        "out-identifier": "order"
      }
    },
    {
      "fire-all-rules": {}
    }
  ]
}

send!

you give success response like below:

{
  "type" : "SUCCESS",
  "msg" : "Container hello-rules_1.0.1-SNAPSHOT successfully called.",
  "result" : {
    "execution-results" : {
      "results" : [ {
        "value" : {"com.myspace.hello_rules.SalesOrder":{
  "amount" : 500.0,
  "region" : "EU",
  "projectCode" : "P999",
  "customer" : "CUSTOMER_ABC",
  "approvalStatus" : "APPROVED",
  "approver" : "SYSTEM"
}},
        "key" : "order"
      } ],
      "facts" : [ {
        "value" : {"org.drools.core.common.DefaultFactHandle":{
  "external-form" : "0:5:2024416239:2024416239:5:DEFAULT:NON_TRAIT:com.myspace.hello_rules.SalesOrder"
}},
        "key" : "order"
      } ]
    }
  }
}

The response is success, because you see approvalStatus = APPROVED, as per defined in the appoval-rules.drl

Try a negative example

change payload to:

{
  "commands": [
    {
      "insert": {
        "object": {
          "com.myspace.hello_rules.SalesOrder": {
            "amount": 500,
            "region": "EU",
            "projectCode": "P999",
            "customer": "CUSTOMER_XYZ"
          }
        },
        "out-identifier": "order"
      }
    },
    {
      "fire-all-rules": {}
    }
  ]
}

send, you will get message below:

{
  "type" : "SUCCESS",
  "msg" : "Container hello-rules_1.0.1-SNAPSHOT successfully called.",
  "result" : {
    "execution-results" : {
      "results" : [ {
        "value" : {"com.myspace.hello_rules.SalesOrder":{
  "amount" : 500.0,
  "region" : "EU",
  "projectCode" : "P999",
  "customer" : "CUSTOMER_XYZ",
  "approvalStatus" : "MANDATORY_SECONDARY_APPROVAL",
  "approver" : "SYSTEM"
}},
        "key" : "order"
      } ],
      "facts" : [ {
        "value" : {"org.drools.core.common.DefaultFactHandle":{
  "external-form" : "0:6:1382839164:1382839164:6:DEFAULT:NON_TRAIT:com.myspace.hello_rules.SalesOrder"
}},
        "key" : "order"
      } ]
    }
  }
}

The response is success but now the approvalStatus = MANDATORY_SECONDARY_APPROVAL, meaning that approval is not success – not approved, as per defined in the appoval-rules.drl.

Benefits

The approval workflow is externalized into a BRE. Business analysts maintain thresholds, exceptions, and conditional logic in a central rule repository. Changes propagate immediately across the ERP system, and the risk of inconsistent rules across modules is eliminated. Approval policies can now evolve rapidly with business strategy, without requiring IT intervention.

Dynamic Approval Workflow with Drools

Related Services

Learn more

  • Dynamic Approval Workflow with Drools
    Business rule automation implementation – using Drools for dynamic approval process where rules assess the order amount and determine the right approval.
  • Understanding Drools Components
    Discover how Drools, Business Central, and KIE Server work together to design, manage, and execute business rules effectively.
  • Installing Drools
    Step-by-step guide to installing Drools with Docker. Learn how to set up Business Central and KIE Server, deploy rules, and verify your installation.

Leave a Reply