Auditing an Entire Workflow

To audit an entire workflow using one single business action, a workflow-wide audit message business action can be applied, enabling the action to be evaluated and log messages for every transition within the workflow. When using a workflow-wide action, there is no need to apply an audit action to each transition individually, which can be a time-consuming task when configuring complicated workflows.

When the Audit Message Framework component is activated on your system, an audit message business action, Workflow Audit Action (ID = AuditMessaging.WorkflowAuditAction), is created in System Setup under the 'Global Business Rules' folder in the 'Workflow Auditing' subfolder. This business action contains JavaScript code that can be used to enable analytics for any workflow out of the box.

Note: If a business action with the ID 'AuditMessaging.WorkflowAuditAction' already exists on your system, the action will not be moved to the 'Workflow Auditing' subfolder upon installation of the Audit Message Framework. The action will be kept where it is.

Applying an Audit Message Business Action to an Entire Workflow

Workflow-wide audit message business actions are assigned to workflows on a workflow-by-workflow basis. To apply a workflow-wide audit message business action:

  1. Navigate to the relevant workflow in System Setup, then right-click and select Edit Workflow.
  2. In the STEP Workflow Designer, click Edit > Edit Audit Action.

  1. Clicking 'Edit Audit Action' displays the Audit Action Editor dialog. Click the ellipsis button () to select the desired audit message business action. In this example, the out-of-the-box 'Workflow Audit Action' business action is shown.

  1. Click Save to apply the audit action to the workflow.

Workflow Audit Action Transition Evaluation

Once applied, the default audit message business action is automatically triggered for each workflow transition and runs during the evaluation phase of transitions, i.e., it is run after the transitions have been evaluated. This ensures access to the reject message(s) before any transition-local actions. The action also runs on the transition going into the initial state of the workflow, sending an audit message when an object enters the workflow.

Sample Audited Workflow

In the following example workflow, there are the 'Proceed' transitions, each going to a different state. When the user selects to Proceed, the transitions are evaluated in the following order: Proceed (State 1), Proceed (State 2), and Proceed (State 3). Each transition is evaluated until one is found that passes the transition conditions.

If all three Proceed transitions are evaluated to be rejected, the Workflow Audit Action will run once and will include information that the transition evaluation was rejected, along with the rejection messages from all three Proceed transitions.

If one of the Proceed transitions is evaluated to be accepted, the Workflow Audit Action will run once and will include information that the transition evaluation was successful.

Important: The Workflow Audit Action should never be used to attempt to make changes to data. Any changes made data in the Workflow Audit Action are rolled back if the evaluated transition is rejected. Audit Messages are sent whether the transition is rejected or not.

Workflow Audit Action JavaScript Code

The following screenshot shows a portion of the JavaScript code for the out-of-the-box Workflow Audit Action business action. The highlighted section of the code is what builds the JSON object that is sent as the audit message. The JSON message is received and handled by the plugin associated with a specific topic; in this case, the Audit Message Receiver JDBC database delivery plugin.

The code in its entirety is provided after the screenshot.

Important: The Workflow Audit Action will not work directly out of the box; a bind must be made to the relevant audit messaging topic in the external JDBC database table before this action can produce an audit message. Refer to the Audit Message Framework JavaScript Binds and Public JavaScript API Methods topic for more details on Audit Message Framework binds.

Script

var nodeID = node.getID();
var userID = manager.getCurrentUser().getID();
var workflowID = workflow.getID();

var event = transitionEvaluation.getEvent();
var eventID = null;
if (event != null) {
   eventID = event.getID();
}

var transitionMessage = transitionEvaluation.getMessage();
var transitionRejected = transitionEvaluation.isRejected();
var resultMessages = transitionEvaluation.getResultMessages();

if (resultMessages.size() === 0) {
   var concatenatedResults = null;
} else {
   var concatenatedResults = "Evaluation Results (" + resultMessages.size() + "): ";
}

var resultMessageIter = resultMessages.iterator();
while (resultMessageIter.hasNext()) {
   concatenatedResults = concatenatedResults + resultMessageIter.next() + "; ";
}

var sourceState = transitionEvaluation.getSource();
var sourceStateID = null;
if (sourceState) {
   sourceStateID = sourceState.getID();
}

var targetState = transitionEvaluation.getTarget();
var targetStateID = null;
if (targetState) {
   targetStateID = targetState.getID();
}

var logTime = new Date().getTime();

// var auditObject = {
//    "_ID": "" + nodeID + "_" + workflowID,
//    ...
// }
var auditObject = {
   "nodeID": "" + nodeID,
   "workflowID": "" + workflowID,
   "userID": "" + userID,
   "logTime": logTime,
   "transition": {
      "eventID": "" + eventID,
      "submitMessage": "" + transitionMessage,
      "sourceStateID": "" + sourceStateID,
      "targetStateID": "" + targetStateID,
      "isRejected": transitionRejected,
      "rejectionMessages": "" + concatenatedResults
   }
};

var auditMessage = JSON.stringify(auditObject);