I needed something similar.
To determine whether the current job is running on orchestrator, I use Split(Environment.CurrentDirectory,"\") to get the nodes in the current directory. In my case if there are .nuget, packages, lib, or net45 nodes, then I know the job is running from orchestrator. This may or may not work for you, depending on your local and published paths.
For notifications, I use a job config table or spreadsheet with columns to control paths, databases, queues, environment setup details, retry strategies, text and email notifications, etc. I include an input parameter to jobs that is the Id for a row in this table. This way job config is set as a batch of values at the beginning of each job. The person notified can be different than the agent who started the job (api, queue ended, scheduled, a different operator).
In terms of getting the Job name using the API, there’s not a Name but there’s a ReleaseName, which is the process on Orchestrator.
- To get job values for the current running job, I 1st need to know the robot’s Id number. You can get this by building a lookup table based on query results of the UiPath.dbo.Robots table where IsDeleted=0, or based on a full retrieval through the API of all (undeleted) Robots.
The Robots API data includes Name, Username, and Id. At runtime you can get the Environment.UserName for the current job. This equals the Name (not the Username) for the database or the API:
Use this value to filter the endpoint you’re using, like this:
From the results, get the Id of your robot.
- After you have the robot’s Id, use that to limit the Jobs endpoint for the API. For instance, if my Robot Id is 123, and I’m on premise, and I want the actively-running job for robot 123, then my endpoint will be something like this:
(When you copy the endpoint from a browser, URL encoding will automatically carry over to Studio.)
From these API results, you can get the ReleaseName or any other job-related values: Key,StartTime,EndTime,State,Source,SourceType,BatchExecutionKey,Info,CreationTime,StartingScheduleId,ReleaseName,Type,InputArguments,OutputArguments,HostMachineName,HasMediaRecorded,PersistenceId,ResumeVersion,StopStrategy,ReleaseVersionId,Id.
It would be easier to get related job information with fewer steps if the RobotId was returned from the API for Jobs-related endpoints. This would match the design of the UiPath.dbo.Jobs table, which includes columns for both RobotId and also CreatorUserId. CreatorUserId relates to the Users table, which has an EmailAddress field. There might be a better way to do these types of lookups (within a running job, at runtime, a way to ask directly, what is my robot Id?, what is my creator Id?), but I haven’t found it. However, using the steps above, I get the information that I want. I’m able to automatically schedule a new job using the API, when some jobs end without finishing their queue, under certain circumstances - which is my goal.