Identifying the Last Job Execution per Robot and Tenant in UiPath Orchestrator

Which robot ran under which tenant, and what was its most recent job execution status?

Purpose

Explains how to retrieve the most recent job executed by each robot in the UiPath Orchestrator database. It includes details such as tenant, robot type, machine name, job status, and extracted process name. This is particularly useful for support, auditing, and performance analysis.


Background

In UiPath Orchestrator environments, it's common to analyze recent execution history per robot for monitoring or troubleshooting. However, jobs are logged continuously, and identifying only the latest job per robot across tenants requires filtering and ranking.


Query :


WITH RankedJobs AS (

SELECT

t.TenancyName AS TenantName,

B.[Name] AS Robot,

CASE

WHEN B.Type = 0 THEN 'NonProduction'

WHEN B.Type = 1 THEN 'Attended'

WHEN B.Type = 2 THEN 'Unattended'

WHEN B.Type = 3 THEN 'Development'

WHEN B.Type = 4 THEN 'StudioX'

WHEN B.Type = 6 THEN 'StudioPro'

ELSE 'Unknown'

END AS RobotType,

J.Id AS JobID,

CONVERT(varchar(200), R.[Name]) +

CASE

WHEN CHARINDEX('ServerList', CONVERT(varchar(300), J.InputArguments)) > 0

THEN '-' + LEFT(SUBSTRING(CONVERT(varchar(300), J.InputArguments), 16, 999), LEN(SUBSTRING(CONVERT(varchar(300), J.InputArguments), 16, 999)) - 2)

ELSE ''

END AS ProcessName,

M.Name AS MachineName,

DATEADD(hh, DATEDIFF(hh, GETUTCDATE(), GETDATE()), J.StartTime) AS Started,

DATEADD(hh, DATEDIFF(hh, GETUTCDATE(), GETDATE()), J.EndTime) AS Finish,

J.StartTime,

CASE

WHEN J.[State] = 0 THEN 'Queued'

WHEN J.[State] = 1 THEN 'Running'

WHEN J.[State] = 2 THEN 'Stopping'

WHEN J.[State] = 3 THEN 'Terminating'

WHEN J.[State] = 4 THEN 'Failed'

WHEN J.[State] = 5 THEN 'Completed'

WHEN J.[State] = 6 THEN 'Canceled'

ELSE CONVERT(varchar(10), J.State)

END AS JobStatus,

J.InputArguments,

ROW_NUMBER() OVER (PARTITION BY B.[Name] ORDER BY J.Id DESC) AS rn

FROM

Jobs J

INNER JOIN Robots B ON J.RobotId = B.Id

INNER JOIN Machines M ON J.MachineId = M.Id

INNER JOIN Releases R ON J.ReleaseId = R.Id

INNER JOIN Tenants t ON J.TenantId = t.Id

)

SELECT *

FROM RankedJobs

WHERE rn = 1

ORDER BY Robot;


Result :