How to retrieve the process name of the currently running orchestrator job at runtime?

I am trying to create a workflow that determines it’s own process name as seen in the below picture

process name

The use case is that we want to add re-useable code to all of our dispatchers. We have had issues where we accidentally run the dispatcher on multiple robots at the same time. We are going to build a function that will check the name of the currently running process, then get the count of actively running jobs with the current name is > 1 If count = 1, then continue. If count > 1 then it should stop.

Getting the list of currently running jobs is easy enough with the ‘Get Jobs’ activity, but I’m struggling to figure out how to get the process name of the job itself.

did you try the Get Jobs activity filtering as you need?

What would I put in the filter? I’m not sure how to get the name of the process/job that is actually running?

i guess you want to filter by running jobs and see what comes out, you make it better from there i guess…

@bcorrea haha yes that is what i was referring to when I said I knew how to filter the jobs. The problem is, I don’t know how to feed the correct information into the filter. Surely the robot knows which process it’s running - I just don’t know how to access that data

Sorry we can never know how proficient in uipath development people are in the forums, so sometimes we might misunderstand peoples problems, did you try running the activity with no filter? Can you iterate through all the jobs returned?

Try filter like this: for process name:
“contains(Release/Name,%27PART_OF_PROCESS_NAME%27)&$orderby=CreationTime%20desc”

@bcorrea I think I didn’t do a very good job of explaining what I’m having trouble with.

I have 3 steps I want to achieve. I know how to do step #2 and step #3, but am not sure how to do step #1:
1. Each robot determines which process it is currently running.
2. Each robot will count how many times the process determined in step 1 is currently running across all robots.
3. If process is running on a robot other than itself, stop itself.

Let’s say I have 3 robots named R1, R2, and R3. Each robot is currently running it’s own process. R1 is running process1, R2 is running process2, and R3 is also running process1. R1 and R2 started their processes slightly before R3.

Based on this example, R1 determines it is running process1, checks to see if other robots are currently running process1, sees that it’s the only one running process1, so it continues. R2 does the same thing. R3 determines it is running process1, sees that R1 is already running process1, so it stops. The end result is that process1 and process2 are only run once.

see above an example of how you need the filter to be, and also you can put there the current robot name, just dont expect the filter to only return one perfect item, because i am really not sure if would be realistic…

@Dave filter input would be (“State eq ‘Running’”)

@StevenWangler that would only provide a list of all the currently running jobs. The issue I was trying to figure out is how to find out the name of the currently running process.

I was able to devise a way eventually. I’m sure there is a better way, but I created a function that reads the project.json (using relative path to get the current project jason only), deserialize it, and pull out the process name from there.

1 Like

Hi Dave, Can you please share the function if possible. I need to do the same thing.

Hi, thanks for sharing filtering options. I was trying to follow uipath recomendations for get job activity and also looked into odata documentation but nowhere could I find such syntax as you have written here - “contains(Release/Name,%27 PART_OF_PROCESS_NAME %27)&$orderby=CreationTime%20desc” . I kept trying to write ProcessName eq ‘MyProcessName’ but kept getting Bad Request error. Where did you find this information on how to write proper filtering syntax? Thanks.

Hi,

If you put the results of Get Jobs in a For each with a local var named ‘item’ and use an ‘If’ statement this will give you the list of running jobs

item.StartTime.ToString.Split(" "c)(0).Contains(Now.ToShortDateString) AND item.State.ToString.ToLower() = “running”

•Get jobs argument type for the For Each: UiPath.Core.Activities.OrchestratorJob
•To get the process name: item.ProcessName
•For documentation; URI Conventions (OData Version 2.0) · OData - the Best Way to REST
The queries I got I found them here on the forum from other users though
image

Hope it helps!