# SyteLine Background Task History Query Generator for TaskMan

> Source: https://netray.co/tools/syteline-background-task-history-query-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Writes read-only SQL against BGTaskHistory and ActiveBGTasks to find failed reports and tasks, slow tasks, stuck queue entries and submissions that never got a history record.

## Category

developer

## Erp

Infor SyteLine

## Audience

- ERP administrator
- SyteLine developer
- DBA

## Tool

**Kind:** template

**Output:** code

**Language:** sql

**Fields:**

#### Days back

**Key:** days_back

**Type:** number

**Default:** 7

#### Task name filter (LIKE)

**Key:** task_filter

**Type:** text

**Default:** %

**Help:** For example %Report% or a single task name.

#### Slow run threshold (seconds)

**Key:** slow_seconds

**Type:** number

**Default:** 600

#### Stuck in queue after (minutes)

**Key:** stuck_minutes

**Type:** number

**Default:** 60

#### Top N failures

**Key:** top_n

**Type:** number

**Default:** 100

#### Column: task number

**Key:** col_num

**Type:** text

**Default:** TaskNumber

**Help:** Confirm with block 0. Every column field can be corrected to your schema.

#### Column: task name

**Key:** col_task

**Type:** text

**Default:** TaskName

#### Column: submission date

**Key:** col_submit

**Type:** text

**Default:** SubmissionDate

#### Column: start date

**Key:** col_start

**Type:** text

**Default:** StartDate

#### Column: completion date

**Key:** col_done

**Type:** text

**Default:** CompletionDate

#### Column: error message

**Key:** col_err

**Type:** text

**Default:** TaskErrorMsg

#### Column: requesting user

**Key:** col_user

**Type:** text

**Default:** RequestingUser

#### Column: return status

**Key:** col_ret

**Type:** text

**Default:** ReturnStatus

**Blocks:**

#### 0. Confirm the column names first

**Body:** SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME IN (N'BGTaskHistory', N'ActiveBGTasks')
ORDER BY TABLE_NAME, ORDINAL_POSITION;

#### 1. Failed runs in the last N days

**Body:** SELECT TOP ({{top_n}})
    h.[{{col_num}}],
    h.[{{col_task}}],
    h.[{{col_user}}],
    h.[{{col_submit}}],
    h.[{{col_start}}],
    h.[{{col_done}}],
    h.[{{col_ret}}],
    h.[{{col_err}}]
FROM dbo.BGTaskHistory h
WHERE h.[{{col_done}}] IS NOT NULL
  AND ISNULL(h.[{{col_err}}], N'') <> N''
  AND h.[{{col_submit}}] >= DATEADD(day, -{{days_back}}, GETDATE())
  AND h.[{{col_task}}] LIKE N'{{task_filter}}'
ORDER BY h.[{{col_done}}] DESC;

#### 2. Run count, success count and duration per task

**Body:** SELECT
    h.[{{col_task}}] AS task_name,
    COUNT(*) AS runs,
    SUM(CASE WHEN h.[{{col_done}}] IS NOT NULL AND ISNULL(h.[{{col_err}}], N'') = N'' THEN 1 ELSE 0 END) AS successful_runs,
    AVG(CAST(DATEDIFF(second, h.[{{col_start}}], h.[{{col_done}}]) AS bigint)) AS avg_duration_s,
    MAX(DATEDIFF(second, h.[{{col_start}}], h.[{{col_done}}])) AS max_duration_s,
    AVG(CAST(DATEDIFF(second, h.[{{col_submit}}], h.[{{col_start}}]) AS bigint)) AS avg_queue_delay_s,
    SUM(CASE WHEN DATEDIFF(second, h.[{{col_start}}], h.[{{col_done}}]) >= {{slow_seconds}} THEN 1 ELSE 0 END) AS slow_runs
FROM dbo.BGTaskHistory h
WHERE h.[{{col_submit}}] >= DATEADD(day, -{{days_back}}, GETDATE())
  AND h.[{{col_task}}] LIKE N'{{task_filter}}'
GROUP BY h.[{{col_task}}]
ORDER BY avg_duration_s DESC;

#### 3. Queue entries waiting longer than the threshold

**Body:** SELECT a.*
FROM dbo.ActiveBGTasks a
WHERE a.[{{col_submit}}] < DATEADD(minute, -{{stuck_minutes}}, GETDATE())
ORDER BY a.[{{col_submit}}];

#### 4. Queue entries with no history record

**Body:** SELECT a.*
FROM dbo.ActiveBGTasks a
WHERE NOT EXISTS (
    SELECT 1
    FROM dbo.BGTaskHistory h
    WHERE h.[{{col_num}}] = a.[{{col_num}}]
)
ORDER BY a.[{{col_submit}}];

**Notes:** ActiveBGTasks is the TaskMan queue and BGTaskHistory holds the run history shown in the Background Task History form. Column names are defaults to be confirmed with block 0 or sp_help 'BGTaskHistory' on your SyteLine 9/10 database; correct any field that differs. Read-only: never delete queue or history rows by hand, use the Active Background Tasks and Background Task History forms.

## Content

**Intro:** This generator writes read-only SQL for monitoring SyteLine 9/10 on-prem TaskMan: which reports and background tasks failed, how long each task runs, what is stuck in the queue, and which submissions never produced a history record. It reads the same rows as the Background Task History form, but you can schedule it, alert on it and filter it any way you like.

**Sections:**

#### How to use it

**Body:** Run block 0 first on the application database and compare the column list with the column fields. The defaults are the commonly used names, but correct any that differ on your version, and the other blocks update instantly. Then set the days back window and an optional task name pattern. Block 1 lists recent failures with the error text. Block 2 gives one row per task with run count, successful runs, average and maximum duration and average time spent waiting in the queue. Block 3 shows queue rows older than your threshold, which usually means TaskMan is stopped, the service account lost access, or a task is hung. Block 4 finds queue rows that never got a history row.

**Bullets:**

- Daily: block 1 for the overnight report and job run
- Weekly: block 2 to spot tasks getting slower as data grows
- On a user complaint: blocks 3 and 4

#### How TaskMan records a run

**Body:** When a user runs a report or a utility from a SyteLine form in background mode, the form submits a row to ActiveBGTasks. TaskMan, the Windows service on the utility server, polls that queue, runs the task (a report through the report server, a stored procedure, or an executable) and updates the row. The matching record in BGTaskHistory is what the Background Task History form shows. Block 2 treats a run as successful when it has a completion date and a blank error message, and measures duration as the seconds between start and completion; adjust that rule if your tasks report failures only through the return status. For executable tasks the return status holds the program's return code, so a non-zero value is worth reading even when the error text is blank.

**Bullets:**

#### Worked example

**Body:** An administrator sets days back to 7 and the filter to %Invoice%. Block 2 returns the invoice print task with 35 runs, 33 successful, an average of 95 seconds and a maximum of 1,480 seconds, with two slow runs above 600 seconds. Block 1 shows the two failures, both with a report server timeout message on Monday morning. Average queue delay of 400 seconds on the same morning suggests TaskMan was busy with month-end jobs. The fix is scheduling, not the report itself: move the heavy jobs out of the morning window or add a second TaskMan instance if your licensing and setup allow it.

**Bullets:**

#### When a report seems to run but nothing appears

**Body:** If a user gets a success message but no output and no history record, check block 4 and the queue. A missing history record often means the submission never reached ActiveBGTasks, so the message on the form was misleading; no history can be written for a request that was never queued. If the row is in the queue but never starts, check that the TaskMan service is running on the utility server, its configuration points at the right application database, and its account can reach the report server. If it starts and fails, the error message in block 1 is usually specific.

**Bullets:**

**Cta:** If you want administrators to ask why last night's SyteLine jobs failed and get an answer from this data on your own servers, we can set up a private AI layer for that.

**Faq:**

#### How do I run a report in SyteLine?

**Answer:** Open the report form, set the ranges and options, and choose Preview to view it on screen or Print to send it to TaskMan as a background task. Background runs are recorded in Background Task History, where you can see status, timing and any error message, and reopen the output.

#### Where is SyteLine background task history stored?

**Answer:** In the BGTaskHistory table in the application database. Requests first land in ActiveBGTasks, the TaskMan queue, and each run is recorded in BGTaskHistory. The Background Task History form reads this table, so any row you query can be checked there, including its error message and output.

#### Why is my SyteLine report stuck in the queue?

**Answer:** Usually because TaskMan is not processing: the service is stopped, it points at a different configuration, or an earlier task is hung. Block 3 lists queue rows older than your threshold. Restart TaskMan through your normal change process and check its log before deleting anything.

#### Is it safe to query BGTaskHistory directly?

**Answer:** Read-only queries with a date filter are safe on a well-indexed system, and better run on a reporting copy if the table is large. Do not delete or update history or queue rows by SQL; use the forms and any purge utility Infor provides so related records stay consistent.

## Search terms

how to run a report in syteline, syteline report, syteline report viewer, syteline reporting, syteline background task history, syteline taskman, syteline bgtaskhistory, syteline report not running

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
