KBEC-00310 - Access Workflow Log through API

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 => <enter "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 = <responses version="2.3" dispatchId="14805" nodeId="192.168.16.102">
<response requestId="2" nodeId="192.168.16.102">
<objectId>logEntry-61a978ea-25b6-11e5-b41a-24ab20524153</objectId>
<objectId>logEntry-61a978ec-25b6-11e5-b41a-24ab20524153</objectId>
<objectId>logEntry-61acfa7d-25b6-11e5-83fa-24ab20524153</objectId>
<objectId>logEntry-62079dad-25b6-11e5-83fa-24ab20524153</objectId>
<objectId>logEntry-62092475-25b6-11e5-94f5-24ab20524153</objectId>
<objectId>logEntry-62097296-25b6-11e5-94f5-24ab20524153</objectId>
<objectId>logEntry-620b6e85-25b6-11e5-907c-24ab20524153</objectId>
<object>
<objectId>logEntry-61a978ea-25b6-11e5-b41a-24ab20524153</objectId>
<logEntry>
<logEntryId>61a978ea-25b6-11e5-b41a-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>Created workflow 'workflow_13_20150708141455'</message>
<principal>admin</principal>
<severity>INFO</severity>
<subject>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>workflow_13_20150708141455</subjectName>
<time>2015-07-08T21:14:55.727Z</time>
</logEntry>
</object>
<object>
<objectId>logEntry-61a978ec-25b6-11e5-b41a-24ab20524153</objectId>
<logEntry>
<logEntryId>61a978ec-25b6-11e5-b41a-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>Starting state: 'S1'</message>
<principal>project: Default</principal>
<severity>INFO</severity>
<subject>state-61a7a41b-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>S1</subjectName>
<time>2015-07-08T21:14:55.727Z</time>
</logEntry>
</object>
<object>
<objectId>logEntry-61acfa7d-25b6-11e5-83fa-24ab20524153</objectId>
<logEntry>
<logEntryId>61acfa7d-25b6-11e5-83fa-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>Invoking the sub-job for state 'S1'</message>
<principal>project: Default</principal>
<severity>INFO</severity>
<subject>state-61a7a41b-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>S1</subjectName>
<time>2015-07-08T21:14:55.758Z</time>
</logEntry>
</object>
<object>
<objectId>logEntry-62079dad-25b6-11e5-83fa-24ab20524153</objectId>
<logEntry>
<logEntryId>62079dad-25b6-11e5-83fa-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>The sub-job 'job_167_20150708141455' for state 'S1' has completed</message>
<principal>project: Default</principal>
<severity>INFO</severity>
<subject>state-61a7a41b-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>S1</subjectName>
<time>2015-07-08T21:14:56.356Z</time>
</logEntry>
</object>
<object>
<objectId>logEntry-62092475-25b6-11e5-94f5-24ab20524153</objectId>
<logEntry>
<logEntryId>62092475-25b6-11e5-94f5-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>Evaluating the condition for onCompletion transition 'T1'</message>
<principal>project: Default</principal>
<severity>INFO</severity>
<subject>transition-61a7cb33-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>T1</subjectName>
<time>2015-07-08T21:14:56.369Z</time>
</logEntry>
</object>
<object>
<objectId>logEntry-62097296-25b6-11e5-94f5-24ab20524153</objectId>
<logEntry>
<logEntryId>62097296-25b6-11e5-94f5-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>Encountered a property reference error when evaluating the condition for onCompletion transition 'T1': Unrecognized path element in '/j;kjh;ljhw"SomeProperty";': 'j;kjh;ljhw'</message>
<principal>project: Default</principal>
<severity>ERROR</severity>
<subject>transition-61a7cb33-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>T1</subjectName>
<time>2015-07-08T21:14:56.369Z</time>
</logEntry>
</object>
<object>
<objectId>logEntry-620b6e85-25b6-11e5-907c-24ab20524153</objectId>
<logEntry>
<logEntryId>620b6e85-25b6-11e5-907c-24ab20524153</logEntryId>
<container>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</container>
<containerName>workflow_13_20150708141455</containerName>
<message>The workflow has automatically completed since the active state has no pending outbound transitions and all subjobs and subworkflows are complete</message>
<principal>project: Default</principal>
<severity>INFO</severity>
<subject>workflow-61a77d07-25b6-11e5-b41a-24ab20524153</subject>
<subjectName>workflow_13_20150708141455</subjectName>
<time>2015-07-08T21:14:56.385Z</time>
</logEntry>
</object>
</response>
</responses>

Applies to

  • Product versions: All versions
Have more questions? Submit a request

Comments

Powered by Zendesk