System Maintenance and Advanced Workflows Finalizing Orders and Updating Admin Statuses

This workflow automates the final stages of order processing by linking QuickBooks Online (QBO) contacts, detecting product bundles, and automatically routing parent orders based on the completion of their subitems.

By implementing this process, you can ensure that orders are only moved to the next stage of fulfillment when all administrative tasks are complete.

Prerequisites

To use this workflow, you will need a valid Monday.com API Key, the Board ID for your QBO Contacts (e.g., 7932413900), and the specific column IDs for your statuses and connected boards.

Workflow Architecture

The order finalization process runs in two distinct phases: fetching the QBO contact and evaluating the order for routing.

flowchart TD
    A["Trigger: Finalize Order"] --> B["Update Status to 'Finalize order'"]
    B --> C["Read Connected Board"]
    C --> D["Fetch QBO Contact ID"]
    D --> E["Check for Bundle Products"]
    E --> F{"Are all subitems 'Admin'?"}
    F -- Yes --> G{"Is Parent Status Empty?"}
    G -- Yes --> H["Update Parent Status to 'Matt'"]
    G -- No --> I["No Action Taken"]
    F -- No --> I["No Action Taken"]

Step-by-Step Process

  1. 1

    Link the QBO Contact

    First, the system updates the current item's status to indicate the order is being finalized. It then reads the connect_boards column to find the linked pulse ID. Using this ID, it queries the QBO Contacts board to retrieve the customer's QBO Contact ID.

  2. 2

    Detect Bundle Orders

    The workflow compares the products in the current order (order_product_ids) against a predefined list of bundle products (bundle_product_ids). If a match is found, the order is flagged as a bundle order.

  3. 3

    Evaluate Subitem Statuses

    Next, the system queries Monday.com to check the statuses of all subitems attached to the parent order. It specifically looks to see if every subitem has been marked as Admin.


    If an order has zero subitems, the system defaults to False (meaning it will not treat the order as having all "Admin" subtasks completed).

  4. 4

    Route the Parent Order

    If all subitems are marked as "Admin" AND the parent order's status is currently empty (or set to "None"), the workflow automatically updates the parent order's status to Matt for final review and processing.

Code Implementation

The routing logic is handled via a Python script that interacts with the Monday.com API.

Ensure your API requests specify the API version in the headers (e.g., "API-Version": "2024-04"). Older versions of the Monday.com API may not support these queries.

import requests

# 1. Check for Bundle Orders
order_product_ids = input_data.get('order_product_ids', '').split(',')
bundle_product_ids = input_data.get('bundle_product_ids', '').split(',')

matching_bundles = set(order_product_ids) & set(bundle_product_ids)
bundle_output = {
    'Bundle Order': 'Yes' if matching_bundles else 'No',
    'Bundle ID': next(iter(matching_bundles)) if matching_bundles else 0
}

# 2. Check Subitems and Route Parent Order
headers = {
    "Authorization": input_data.get('monday_api_key'),
    "Content-Type": "application/json",
    "API-Version": "2024-04" 
}

# (GraphQL query execution omitted for brevity - see Accordion below)

if subitems:
    # Check if all subitems have the 'Admin' status
    all_admin = all(s['column_values'][0]['text'] == 'Admin' for s in subitems)
else:
    all_admin = False

# Logic: All Admin + Parent Status is None/Empty
if all_admin and (not parent_status or parent_status == "None"):
    # Update parent status to "Matt"
    mut_vars = {
        "item": parent_id,
        "board": board_id,
        "val": "Matt"
    }
    # Execute mutation...
View the GraphQL Queries

Fetching Subitems and Parent Status:

query ($id: [ID!]) {
  items (ids: $id) {
    board { id }
    column_values (ids: ["status_mkm1amqe"]) {
      text
    }
    subitems {
      column_values (ids: ["color_mkszrf28"]) {
        text
      }
    }
  }
}

Mutating the Parent Status:

mutation ($item: ID!, $board: ID!, $val: String!) {
  change_simple_column_value (item_id: $item, board_id: $board, column_id: "status_mkm1amqe", value: $val) {
    id
  }
}

Expected Outputs

After the workflow completes, it generates a combined output payload containing both the bundle detection results and the Monday.com update status.

Output VariableTypeDescription
idStringThe ID of the processed parent item.
QBO Contact IDStringThe QuickBooks Online contact ID retrieved from the connected board.
Bundle OrderStringReturns Yes if bundle products were detected, otherwise No.
Bundle IDString / IntegerThe specific ID of the matched bundle product, or 0 if none.
update_statusStringA message indicating the result of the routing attempt (e.g., Success: Changed to Matt or No action taken).

Use the update_status variable in subsequent steps of your automation to trigger notifications (like a Slack message or email) only when an order is successfully routed to a team member.