KBEC-00230 - Recovering the user that authorized a state transition

Article ID:360033192311
1 minute readKnowledge base

Description

It would be convenient if the name of the person who initiated a manual transition were readily available.

Solution

The name is available from the Commander Workflow Log. In the UI, clicking on the "View Log" link on the top right corner of the workflow section. Navigate to the transition in question and the name of the user you initiated the manual transition is available.

Given a state name and a workflow name, the below Perl script retrieves the user that authorized a state transition.

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 $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";