Auditing by Workflow Transition

An alternative to auditing an entire workflow with a single default audit messaging business action is to audit workflows at the transition level. Audit business actions can be used on individual transitions instead of or in addition to a default workflow-wide business action. If used in addition to a default auditing business action, the actions applied at the transition level will be evaluated after the workflow-default rule.

The Audit Message Topic bind can be used to send messages like the two following examples, each of which creates a JSON message object and uses the bind's API sendMessageAsync method. The JSON message is received and handled by the plugin associated with a specific topic; in this case, the out-of-the-box Audit Message Receiver JDBC database delivery plugin.

Note: The sample business actions in this topic are not automatically created in your system upon activation of the Audit Message Framework component. Additionally, the provided JavaScript may need alterations to conform to your specific business requirements.

Sample JavaScript for a Workflow Business Condition Failure

The following script sends an audit message if a condition in a workflow fails:

Script

var attributeValue = node.getValue(attribute.getID()).getSimpleValue();
	
if (attributeValue) {
	// Attribute has a value. Everything is OK.
	return true;
} else {
	// Attribute does not have a value. Log the transition as failed.
	var nodeID = node.getID();
	var userID = manager.getCurrentUser().getID();
	var workflowID = workflow.getID();
 
	var event = transition.getEvent();
	var eventID = null;
	if (event != null) {
		eventID = event.getID();
	}
	
	var transitionMessage = transition.getMessage();
 
	var sourceState = transition.getSource();
	var sourceStateID = null;
	if (sourceState) {
		sourceStateID = sourceState.getID();
	}
	
	var targetState = transition.getTarget();
	var targetStateID = null;
	if (targetState) {
		targetStateID = targetState.getID();
	}
	
	var logTime = new Date().getTime();
	var rejectMessage = "Condition failed because " + attribute.getID() + " does not have a value";
	
	// Build JSON object for message
	var auditObject = {
		"nodeID": "" + nodeID,
		"workflowID": "" + workflowID,
		"transition": {
			"eventID": "" + eventID,
			"submitMessage": "" + transitionMessage,
			"sourceStateID": "" + sourceStateID,
			"targetStateID": "" + targetStateID
		},
		"logTime": logTime,
		"rejectMessage" : rejectMessage
	};
 
	var auditMessage = JSON.stringify(auditObject);
 
	// Send the audit message to the audit message framework
	topic.sendMessageAsync(auditMessage);
	return false;
}

Sample JavaScript for a Workflow State On Entry Audit Message

The following script sends an audit message when a specified object enters a specified workflow state:

Script

var nodeID = node.getID();
var userID = manager.getCurrentUser().getID();
var workflowID = workflow.getID();
 
var event = transition.getEvent();
var eventID = null;
if (event != null) {
	eventID = event.getID();
}
 
var transitionMessage = transition.getMessage();
 
var sourceState = transition.getSource();
var sourceStateID = null;
if (sourceState) {
	sourceStateID = sourceState.getID();
}
 
var targetState = transition.getTarget();
var targetStateID = null;
if (targetState) {
	targetStateID = targetState.getID();
}
 
var taskAssigneeID = null;
var taskEntryTime = null;
var taskDeadline = null;
 
var task = node.getTaskByID(workflow.getID(), targetState.getID());
if (task) {
	taskAssigneeID = task.getAssignee().getID();
	taskEntryTime = task.getEntryTime();
	taskDeadline = task.getDeadline();
}
// Build JSON object for message
var auditObject = {
	"nodeID": "" + nodeID,
	"workflowID": "" + workflowID,
	"userID": "" + userID,
	"transition": {
		"eventID": "" + eventID,
		"submitMessage": "" + transitionMessage,
		"sourceStateID": "" + sourceStateID,
		"targetStateID": "" + targetStateID
	},
	"task": {
		"assigneeID": "" + taskAssigneeID,
		"entryTime": "" + taskEntryTime,
		"deadline": "" + taskDeadline
	}
};
 
var auditMessage = JSON.stringify(auditObject);
 
// Send the audit message to the audit message framework
topic.sendMessageAsync(auditMessage);