Spread the love

In the previous episodes, we established why I dropped GitHub Copilot for Roo Code and how we set up the “Agentic” workflow. We built the rules, configured the agents, and initialized the memory bank.

Now, we finally start coding. But even here, the process is different from the typical “Vibe Coding” you see in most tutorials. We don’t just ask the AI to “build an integration.” We stick to the plan.

Here is how we moved from a raw JSON payload to actual Business Central staging tables using the multi-agent workflow.

1. The Payload: Defining the Truth

Before we write AL code, we need to know what data we are dealing with. I started by asking Claude to generate a sample payload.json file.

{
  "webshopOrderNo": "WEB-2024-001234",
  "orderDate": "2024-11-20T14:30:00Z",
  "customerEmail": "john.smith@example.com",
  "customerName": "John Smith",
  "customerPhone": "+45 12 34 56 78",
  "billingAddress": {
    "name": "John Smith",
    "address": "Hovedgaden 123",
    "address2": "2. sal",
    "city": "København",
    "postCode": "2100",
    "countryRegionCode": "DK"
  },
  "shippingAddress": {
    "name": "John Smith",
    "address": "Hovedgaden 123",
    "address2": "2. sal",
    "city": "København",
    "postCode": "2100",
    "countryRegionCode": "DK"
  },
  "paymentMethod": "Credit Card",
  "paymentReference": "PAY-CC-789456123",
  "paymentStatus": "Paid",
  "shippingMethod": "Standard Delivery",
  "shippingCost": 49.00,
  "currency": "DKK",
  "orderTotal": 1847.50,
  "orderSubtotal": 1798.50,
  "taxAmount": 359.70,
  "discountAmount": 0.00,
  "customerNote": "Please ring doorbell twice",
  "internalNote": "",
  "orderLines": [
    {
      "lineNo": 1,
      "webshopProductId": "PROD-12345",
      "productSKU": "LAP-DELL-XPS13",
      "description": "Dell XPS 13 Laptop - 16GB RAM, 512GB SSD",
      "quantity": 1,
      "unitPrice": 1299.00,
      "lineAmount": 1299.00,
      "discountPercent": 0.00,
      "discountAmount": 0.00,
      "taxPercent": 25.00,
      "taxAmount": 259.80
    },
    {
      "lineNo": 2,
      "webshopProductId": "PROD-67890",
      "productSKU": "MOUSE-LOG-MX3",
      "description": "Logitech MX Master 3 Mouse",
      "quantity": 2,
      "unitPrice": 99.00,
      "lineAmount": 198.00,
      "discountPercent": 0.00,
      "discountAmount": 0.00,
      "taxPercent": 25.00,
      "taxAmount": 39.60
    },
    {
      "lineNo": 3,
      "webshopProductId": "PROD-45678",
      "productSKU": "KB-LOG-K380",
      "description": "Logitech K380 Wireless Keyboard",
      "quantity": 1,
      "unitPrice": 252.50,
      "lineAmount": 252.50,
      "discountPercent": 0.00,
      "discountAmount": 0.00,
      "taxPercent": 25.00,
      "taxAmount": 50.50
    },
    {
      "lineNo": 4,
      "webshopProductId": "PROD-99999",
      "productSKU": "SHIPPING",
      "description": "Standard Delivery",
      "quantity": 1,
      "unitPrice": 49.00,
      "lineAmount": 49.00,
      "discountPercent": 0.00,
      "discountAmount": 0.00,
      "taxPercent": 25.00,
      "taxAmount": 9.80
    }
  ]
}

This file acts as our “source of truth.” It contains the billing address, shipping address, payment details, and order lines. Instead of guessing the fields, I fed this file to the Orchestrator and gave a clear instruction:

“The staging tables should have the fields defined in my payload.json file.”

This ensures that our database structure matches the incoming data exactly.

2. Refining the Implementation Plan (Not Coding Yet!)

This is where “Agentic Coding” differs from “Vibe Coding.” Even with the JSON file, I did not tell the AI to start coding yet.

I asked the Orchestrator to update the implementation.md file first.

We iterated on several key architectural decisions:

  • Field Mapping: We decided to handle specific field mapping “as we go” rather than pre-defining everything.
  • Error Handling: No emails. No automatic retries. If something fails, the user fixes the data in the staging table and retries manually.
  • Number Series: We will use the standard sales order number series.
  • Primary Keys: We explicitly defined that Web Shop No. combined with a Line No. would form the primary key for lines.

I updated the plan multiple times, explicitly stating: “Do not code anything yet. Only update the MD file.”.

Why spend 15 minutes on a text file? Because in an enterprise environment, you need control. If you just “vibe code,” you get a working prototype that is a nightmare to maintain. If you “agentic code,” you get a system that follows your architectural standards.

3. Executing Phase 1

Once the plan was solid, I finally gave the green light:

“Please implement Phase 1… but only Phase 1.”

The agent went to work. It created the Staging Header and Staging Line tables. It set the fields to Text[1024] to prevent truncation errors, implemented the Enums (or Options in this initial pass), and set up the correct table relations.

4. Handling Real-World Hiccups

It wouldn’t be a “real-world” series if everything went perfectly.

Midway through, I realized I hadn’t pulled the latest changes, so my memory-bank folder was missing. This is a common reality when working with Git.

Instead of panicking, I simply asked the agent to re-initialize the memory bank. It scanned the current project state and rebuilt the context files.

We also hit some latency with Gemini (the Orchestrator), which required a few retries. Since I am using the free/high-traffic tier of Gemini via OpenRouter, this is expected. But because Roo Code handles retries automatically, it was just a minor delay rather than a blocker.

Next Steps

We now have our Staging Tables deployed. The foundation is laid.

In the next episode, we will move faster. Now that the documentation and structure are set, we can start building the API pages and the processing logic to turn this staging data into real Sales Orders.

Leave a Reply