Video Guide:

Automate Your Document Archiving with a Simple Bot Script: Step-by-Step Guide

Manual document archiving wastes time, increases errors, and isn’t scalable. Automating this process is not just a nice-to-have—it’s essential if you want to keep your business organized and compliant. Below, I’ll walk you through creating a bot script that automatically archives sales orders, purchase orders, and work orders based on their age and status. If you follow these steps, you’ll reduce manual work, lower risk, and gain back valuable hours each month.

Step 1: Define Script Parameters

Start by declaring key variables:

  • Max execution duration: How long should the script run? (Set in minutes. Example: 5 minutes)
  • Max documents: Maximum number of documents to process per run. (Set to 10 in this example. Don’t mix this up with deletion; this is for archiving.)
  • Document age threshold: How old does a document need to be before it’s archived? (Example: 3 days)
  • ID storage: Prepare variables or lists to collect IDs for each document type (sales, purchase, work orders).

Tip: If you set your limits too high, you risk running out of time or resources. Start small and scale up.

Step 2: Query Document IDs for Archiving

The script now needs to find eligible documents:

  • Import data: Access your sales orders, purchase orders, and work orders from your database.
  • Filter documents: For each type, retrieve IDs based on:
    • Date range: From 3 days ago to today (or your chosen age).
    • Status:
      • Sales/Purchase Orders: completed, avoided, or returned
      • Work Orders: completed or voided

Repeat this step for all three document types. Store their IDs in separate lists.

Step 3: Adjust for Real Document Count

Prevent unnecessary processing:

  • Count IDs: Calculate the total number of documents found across all lists.
  • Update max documents if needed: If the total is less than your preset maximum, lower the max to the actual count. This avoids empty iterations and wasted cycles.

Step 4: Archive Documents in a Loop

Here’s the core logic:

  • Loop: Run a loop up to your adjusted max document count.
    • Timeout check: On each iteration, verify if the script is about to exceed its maximum run time. If yes, halt immediately.
    • ID existence check: Before processing, confirm that IDs exist in your lists. If a list is empty, log this as a system message (don’t just fail silently).
    • Process and archive:
      • Display the current document ID (use a browser or log message).
      • Wait briefly (e.g., 1 second) for processing and visibility.
      • Execute the archive action (never delete).
      • Check for errors—if archiving fails, print/log a clear system message specific to the failure.

Repeat this for each document type: sales orders, purchase orders, and work orders. Make sure your log or browser message always indicates what type of document is being archived.

Step 5: Apply to All Document Types

Duplicate the logic for purchase orders and work orders. Use the correct ID lists and adjust status checks as described. Messages and logs must clearly state which type is being processed.

Step 6: Schedule Regular Script Execution

Manual runs are pointless if you forget to do them. Automate it:

  • Go to scheduling: Use your system’s scheduler for script execution.
  • Prerequisite: Make sure you’ve configured a valid user IP for automation.
  • Set schedule: Example—run every day at 08:00.
  • Enable: Confirm the schedule. Your bot now runs without your intervention.

Final Notes and Results

After execution, refresh your dashboard and include archived documents in your view. You should see that all documents fitting your age and status criteria are archived, not deleted. Your records are now organized—without manual work.

Bottom line: This approach isn’t just “automation for the sake of it”—it’s about eliminating wasted time, preventing errors, and enforcing process discipline. If you want your business to scale, this is the baseline standard. Anything less is just busywork.

Read More

Related Posts

💬 Start Chat