KBEC-00310 - Access Workflow Log through API

Article ID:360032827792
2 minute readKnowledge base

Summary

Workflows have a "View Log" icon that records every action taken in a workflow.
How do you access the same information through the API?

Solution

The following simple findObjects query can be used to get an xml output of the information you will find in a Workflow Log.

The input for this findObjects request would be "workflow-UUID" in versions 5.x and higher. For versions prior to 5.x, it would be "workflow-ID"

#This script can be run as a Command step in a standalone procedure as well.
#To do so, create a parameter called objectId which will take a value in the format 'workflow-ID'. ID would be UUID for versions 5.x and above.

use ElectricCommander();
my $cmdr = new ElectricCommander();
#Uncomment the following line if you want to run this in a procedure step.
#my $object = $cmdr->getProperty('/myJob/objectid')->findvalue('/responses/response/property/value');


my $xPath = $cmdr->findObjects("logEntry",
 {maxIds => "500",
 numObjects => "20",
 filter => [{propertyName => "container",
 operator => "equals",
 operand1 => "workflow-UUID" here>},
 {operator => "or",
 filter => [{propertyName => "severity",
 operator => "equals",
 operand1 => "INFO"},
 {propertyName => "severity",
 operator => "equals",
 operand1 => "WARN"},
 {propertyName => "severity",
 operator => "equals",
 operand1 => "ERROR"}]}]});
print "result = " . $xPath-> findnodes_as_string("/") . "\n";

Examples

Example code and output of a workflow: workflow-61a77d07-25b6-11e5-b41a-24ab20524153

use ElectricCommander(); my $cmdr = new ElectricCommander(); #Uncomment the following line if you want to run this in a procedure step. #my $object = $cmdr->getProperty('/myJob/objectid')->findvalue('/responses/response/property/value'); my $xPath = $cmdr->findObjects("logEntry",
 {maxIds => "500",
 numObjects => "20",
 filter => [{propertyName => "container",
 operator => "equals",
 operand1 => "workflow-61a77d07-25b6-11e5-b41a-24ab20524153},
 {operator => "or",
 filter => [{propertyName => "severity",
 operator => "equals",
 operand1 => "INFO"},
 {propertyName => "severity",
 operator => "equals",
 operand1 => "WARN"},
 {propertyName => "severity",
 operator => "equals",
 operand1 => "ERROR"}]}]});
print "result = " . $xPath-> findnodes_as_string("/") . "\n";

Output

result =

logEntry-61a978ea-25b6-11e5-b41a-24ab20524153
logEntry-61a978ec-25b6-11e5-b41a-24ab20524153
logEntry-61acfa7d-25b6-11e5-83fa-24ab20524153
logEntry-62079dad-25b6-11e5-83fa-24ab20524153
logEntry-62092475-25b6-11e5-94f5-24ab20524153
logEntry-62097296-25b6-11e5-94f5-24ab20524153
logEntry-620b6e85-25b6-11e5-907c-24ab20524153

logEntry-61a978ea-25b6-11e5-b41a-24ab20524153

61a978ea-25b6-11e5-b41a-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
Created workflow 'workflow_13_20150708141455'
admin
INFO
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
2015-07-08T21:14:55.727Z

logEntry-61a978ec-25b6-11e5-b41a-24ab20524153

61a978ec-25b6-11e5-b41a-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
Starting state: 'S1'
project: Default
INFO
state-61a7a41b-25b6-11e5-b41a-24ab20524153
S1
2015-07-08T21:14:55.727Z

logEntry-61acfa7d-25b6-11e5-83fa-24ab20524153

61acfa7d-25b6-11e5-83fa-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
Invoking the sub-job for state 'S1'
project: Default
INFO
state-61a7a41b-25b6-11e5-b41a-24ab20524153
S1
2015-07-08T21:14:55.758Z

logEntry-62079dad-25b6-11e5-83fa-24ab20524153

62079dad-25b6-11e5-83fa-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
The sub-job 'job_167_20150708141455' for state 'S1' has completed
project: Default
INFO
state-61a7a41b-25b6-11e5-b41a-24ab20524153
S1
2015-07-08T21:14:56.356Z

logEntry-62092475-25b6-11e5-94f5-24ab20524153

62092475-25b6-11e5-94f5-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
Evaluating the condition for onCompletion transition 'T1'
project: Default
INFO
transition-61a7cb33-25b6-11e5-b41a-24ab20524153
T1
2015-07-08T21:14:56.369Z

logEntry-62097296-25b6-11e5-94f5-24ab20524153

62097296-25b6-11e5-94f5-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
Encountered a property reference error when evaluating the condition for onCompletion transition 'T1': Unrecognized path element in '/j;kjh;ljhwhttps://wiki.electric-cloud.com/pages/createpage.action?spaceKey=ec&title=%22SomeProperty%22&linkCreation=true&fromPageId=44663124;': 'j;kjh;ljhw'
project: Default
ERROR
transition-61a7cb33-25b6-11e5-b41a-24ab20524153
T1
2015-07-08T21:14:56.369Z

logEntry-620b6e85-25b6-11e5-907c-24ab20524153

620b6e85-25b6-11e5-907c-24ab20524153
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
The workflow has automatically completed since the active state has no pending outbound transitions and all subjobs and subworkflows are complete
project: Default
INFO
workflow-61a77d07-25b6-11e5-b41a-24ab20524153
workflow_13_20150708141455
2015-07-08T21:14:56.385Z

Applies to

  • Product versions: All versions