Work Queue Processor

Reads items from a queue source, processes each with per-item error isolation using BLOCK/ON BLOCK ERROR, and tracks status per record.

View in Notion

Problem this solves

One bad record kills the entire batch; need per-item error isolation.

Cross-references: Excel Reader to Datatable for loading queue items from Excel. Checkpoint & Resume for crash recovery across runs. Legacy App Data Entry Loop for the actual processing logic inside the BLOCK.

1Load Queue Items

Reads queue items from the source (Excel, CSV, or any DataTable). Sets up counters and results tracking. Variables: varSourceFilePath (path to queue source), varCurrentMessage (logging), ExcelInstance (Excel session), varQueueItems (output — DataTable of queue items), varTotalItems (total count), varProcessedCount (counter), varSuccessCount (counter), varFailCount (counter), varResultsTable (outcome tracking)

PAD Script
1**REGION Load Queue Items
2SET varSourceFilePath TO $'''C:\\\\Data\\\\WorkQueue.xlsx'''
3SET varCurrentMessage TO $fx'Loading queue: ${varSourceFilePath}'
4
5Excel.LaunchExcel.LaunchAndOpen Path: $fx'=${varSourceFilePath}' Visible: False ReadOnly: True LoadAddInsAndMacros: False UseMachineLocale: False Instance=> ExcelInstance
6ON ERROR REPEAT 1 TIMES WAIT 2
7END
8
9Excel.ReadFromExcel.ReadAllCells Instance: $fx'=ExcelInstance' GetCellContentsMode: Excel.GetCellContentsMode.TypedValues FirstLineIsHeader: True RangeValue=> varQueueItems
10ON ERROR REPEAT 1 TIMES WAIT 2
11END
12
13Excel.CloseExcel.Close Instance: $fx'=ExcelInstance'
14ON ERROR REPEAT 1 TIMES WAIT 2
15END
16
17SET varTotalItems TO $fx'= Count(varQueueItems)'
18SET varProcessedCount TO $fx'=0'
19SET varSuccessCount TO $fx'=0'
20SET varFailCount TO $fx'=0'
21
22Variables.CreateNewDatatable InputTable: { ^['ItemIndex', 'Status', 'ErrorMessage'] } DataTable=> varResultsTable
23SET varCurrentMessage TO $fx'Queue loaded — ${varTotalItems} item(s) to process'
24**ENDREGION

2Process Queue with Per-Item Error Isolation

The core loop. Each item is processed inside a BLOCK with ON BLOCK ERROR so that failures are caught and logged without stopping the loop. The BLOCK catches ANY error from any action inside it — providing true per-item isolation. Variables: varQueueItems (queue DataTable), TransactionItem (loop iterator), varProcessedCount (counter), varSuccessCount (counter), varFailCount (counter), varResultsTable (tracking), varCurrentMessage (logging), varTotalItems (total)

PAD Script
1**REGION Process Queue with Error Isolation
2SET varCurrentMessage TO $'''Starting queue processing loop'''
3
4LOOP FOREACH TransactionItem IN varQueueItems
5
6 # Safe stop check
7 IF (FlowControl.IfSafeStop ShouldStop: True) THEN
8 SET varCurrentMessage TO $fx'Safe stop requested after ${varProcessedCount} items'
9 GOTO 'QueueComplete'
10 END
11
12 Variables.IncreaseVariable Value: $fx'=varProcessedCount' IncrementValue: $fx'=1' Result=> varProcessedCount
13 SET varCurrentMessage TO $fx'Processing item ${varProcessedCount} of ${varTotalItems}'
14
15 # BLOCK provides per-item error isolation
16 BLOCK 'ProcessItem'
17 ON BLOCK ERROR
18 # Item failed — log error and continue to next item
19 Variables.IncreaseVariable Value: $fx'=varFailCount' IncrementValue: $fx'=1' Result=> varFailCount
20 Variables.AddRowToDataTable.AppendRowToDataTable DataTable: $fx'=varResultsTable' RowToAdd: $fx'[${varProcessedCount}, Failed, ${LastError.message}]'
21 SET varCurrentMessage TO $fx'Item ${varProcessedCount} FAILED: ${LastError.message}'
22
23 Workstation.TakeScreenshot.TakeScreenshotOfForegroundWindow _
24 ON ERROR REPEAT 1 TIMES WAIT 2
25 END
26 END
27
28 # ====================================
29 # INSERT YOUR PROCESSING LOGIC HERE
30 # ====================================
31 # Examples:
32 # - Data entry via Legacy App Data Entry Loop
33 # - API call via REST API POST Caller
34 # - File operation via Folder Scanner patterns
35 #
36 # Access columns: TransactionItem.ColumnName
37 # Any error in this block jumps to ON BLOCK ERROR above
38
39 SET varCurrentMessage TO $fx'Item ${varProcessedCount} processing...'
40
41 # Placeholder: simulate work with a WAIT
42 WAIT $fx'=1'
43
44 # If we get here, the item succeeded
45 Variables.IncreaseVariable Value: $fx'=varSuccessCount' IncrementValue: $fx'=1' Result=> varSuccessCount
46 Variables.AddRowToDataTable.AppendRowToDataTable DataTable: $fx'=varResultsTable' RowToAdd: $fx'[${varProcessedCount}, Success, ]'
47
48 END
49
50 SET varCurrentMessage TO $fx'Item ${varProcessedCount} done — S: ${varSuccessCount} F: ${varFailCount}'
51
52END
53
54LABEL 'QueueComplete'
55SET varCurrentMessage TO $fx'Queue complete — ${varProcessedCount} processed, ${varSuccessCount} success, ${varFailCount} failed'
56**ENDREGION

3Write Results Report

Exports the per-item results to CSV for audit. Variables: varResultsTable (results DataTable), varResultsPath (output path), varCurrentMessage (logging)

PAD Script
1**REGION Write Results Report
2SET varResultsPath TO $'''C:\\\\Data\\\\Output\\\\QueueResults.csv'''
3SET varCurrentMessage TO $fx'Writing results to: ${varResultsPath}'
4
5File.WriteToCSVFile.WriteCSV VariableToWrite: $fx'=varResultsTable' CSVFile: $fx'=${varResultsPath}' CsvFileEncoding: File.CSVEncoding.UTF8 IncludeColumnNames: True IfFileExists: File.IfFileExists.Overwrite ColumnsSeparator: File.CSVColumnsSeparator.SystemDefault
6ON ERROR REPEAT 1 TIMES WAIT 2
7END
8
9SET varCurrentMessage TO $fx'Results written: ${varSuccessCount} success, ${varFailCount} failed'
10**ENDREGION

Variable Reference Summary

VariableTypeUsed InPurpose
`varSourceFilePath`TextPattern 1Path to queue source file
`varCurrentMessage`TextAll patternsLogging message for Subflow_Logging
`ExcelInstance`Excel InstancePattern 1Excel session handle
`varQueueItems`DataTablePatterns 1, 2Queue items to process
`varTotalItems`NumericPatterns 1, 2Total items in queue
`varProcessedCount`NumericAll patternsItems processed counter
`varSuccessCount`NumericAll patternsSuccessful items counter
`varFailCount`NumericAll patternsFailed items counter
`varResultsTable`DataTablePatterns 1–3Per-item outcome tracking
`TransactionItem`DataRowPattern 2Current queue item in loop
`varResultsPath`TextPattern 3Output CSV path for results

Notes

  • BLOCK / ON BLOCK ERROR is the key. This is what provides per-item error isolation. Any error from ANY action inside the BLOCK jumps to ON BLOCK ERROR, logs the failure, and the LOOP continues to the next item. Without BLOCK, one error kills the entire loop.
  • LastError.message — Available inside ON BLOCK ERROR to capture the error message from whatever action failed. Use this for the results table error column.
  • Processing logic goes inside the BLOCK. Replace the placeholder WAIT with your actual processing — data entry, API calls, file operations, etc. Keep the success counter increment and results logging AFTER the processing logic but BEFORE the BLOCK END.
  • BLOCK syntax (from reference Section 7): BLOCK 'Name' / ON BLOCK ERROR / ...error handling... / END / ...normal actions... / END. The ON BLOCK ERROR section comes first, then the normal actions, then both close with END.
  • Safe stop check. FlowControl.IfSafeStop at the top of the loop allows graceful termination between items.
  • Screenshot in error handler. The screenshot has its own ON ERROR REPEAT so a screenshot failure doesn't cascade.
  • Simple ON ERROR on action-level statements. No ON ERROR on SET or IF.

Dependencies

  • Excel Reader to Datatable
  • Checkpoint & Resume
  • Legacy App Data Entry Loop