x
login Signup

How can you get the previous state for an ElectricCommander workflow?

How can you get the previous state for a workflow?

avatar image By deleted 613 asked Sep 21, 2012 at 05:09 PM
more ▼
(comments are locked)
10|750 characters needed characters left

1 answer: sort voted first

I am able to do this using xpath. If XML schema changes in a future release then this solution likely will not work. It works as of ElectricCommander 4.1.x.

I used findObjects API on "logEntry". This returns items that are shown in "View Log" link on the Workflow Details page.

I notice an inaccuracy in this approach when the transition taken was an "On Enter" transition. In this case, the previous state returned is the previous state that exited with "On Complete" transition.

 use strict;
 use ElectricCommander;
 $| = 1;
 
 my $workflowName = '$[/myWorkflow/workflowName]';
 my $projectName = '$[/myWorkflow/projectName]';
 
 my $ec = new ElectricCommander();
 
 my $xPath = $ec->findObjects("logEntry", {
     filter => {    propertyName => "containerName" ,
                 operator => "equals" ,
                 operand1 => "$workflowName" }
     });
 #my $string = $xPath->findnodes_as_string("/");
 #print "$string \n";
 
 my $activeState = $ec->getWorkflow ($projectName, $workflowName)->findnodes("//activeState")->string_value();
 print "Active state: $activeState \n";
 
 my $totalCount = $xPath->findnodes_as_string("count(//logEntry/subject[contains(., 'state')])");
 #print "Total count: $totalCount \n";
 
 my $previousState;
 my $previousStateCount = $totalCount;
 do {
     $previousStateCount--;
     $previousState = $xPath->findnodes("(//logEntry[contains(subject, 'state')]/subjectName)[$previousStateCount]")->string_value();
 } while ($previousState eq $activeState);
     
 print "Previous state: $previousState \n";


avatar image By amalik 16 answered Sep 21, 2012 at 07:57 PM
more ▼
(comments are locked)
avatar image deleted Sep 26, 2012 at 11:32 AM

Update: This works on EC4.0 as well.

Thanks!

10|750 characters needed characters left
Your answer
toggle preview:

Up to 8 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.