I am writing a javascript property to return the user that started a job.
For manually run procedures I just return `myJob.launchedByUser`. For scheduled procedures I can rely on `myJob.launchedByUser` being blank.
The problem comes when I start working with workflows. I can get the user that started the workflow easily enough by using `myWorkflow.launchedByUser`, but that is not the user that started this job when using a manual transition.
Looking through the documentation and playing around with getProperty I cannot find a way to find the user that clicked the manual transition. Does anyone know how I can find out this information?
Answer by nikhil · Feb 20, 2013 at 09:46 PM
You can capture the user who took the manual transition by specifying it as a parameter on the target state and passing in `$[/myUser/userName]` in the manual transition.
Here is a description.
This workflow contains
State1- Starting state that has a manual transition, named Trans1, to State2
State2- Action that launches a procedure that has one parameter `'userName'` filled in with $[/myState/userName]
Trans1- A manual transition that takes the workflow from State1 to State2 and populates the `userName` parameter on State2 with `$[/myUser/userName]`
At run time the user is not prompted to fill in any information when taking the manual transition because the `userName` parameter was not marked as `defer`.
Answer by amalik · Feb 06, 2013 at 03:20 PM
The user who performed manual transition is logged in the "View Log" link on the workflow details page.
A while ago I wrote a perl script to fetch the *last* user to perform manual transition on a given state. The complexity is because you can take the same manual transition multiple times in the same workflow because you can implement loops hence the need for *last* user.
See the code below. May be you can re-purpose this script for your use.
The two inputs are: 1) State definition name and 2) Workflow name.
use strict; use ElectricCommander; $| = 1; my $state = "state1_transition"; my $workflowName = "workflow_44_201206291819"; my $ec = new ElectricCommander(); my $xPath = $ec->findObjects("logEntry", { filter => { propertyName => "containerName" , operator => "equals" , operand1 => "$workflowName" } }); #my $string = $xPath->findnodes_as_string("//workflow[completed = 0]"); #print "$string \n"; my $countOfLastTransition = $xPath->findnodes_as_string("count(//logEntry[subjectName = '$state'])"); #print "$countOfLastTransition" . "\n"; my $principal = $xPath->findnodes("(//logEntry[subjectName = '$state']/principal)[$countOfLastTransition]")->string_value(); my $time = $xPath->findnodes("(//logEntry[subjectName = '$state']/time)[$countOfLastTransition]")->string_value(); print "Most recent transition of \"$state\" was taken at $time, by user \"$principal\"" . "\n";
How do we use a property at a workflow as a step's run condition? 2 Answers
Create a property in a workflow during runtime 4 Answers
How to access job properties from a different workflow state 1 Answer
Is there an outcome property for a workflow? 3 Answers
Passing values between subworkflows 1 Answer
Electric Cloud powers Continuous Delivery, helping organizations developing deliver better software faster by automating and accelerating build, test, and deployment processes at scale. Industry leaders like Qualcomm, SpaceX, Cisco, GE, Gap, and E*TRADE use Electric Cloud solutions to boost DevOps productivity and Agile throughput.