Audit Message Framework Example Message

To send an audit message, it is necessary to either create a JavaScript bind to an audit message topic or to find an audit message topic via the API. For more information on these binds and topics, refer to the Audit Message Framework JavaScript Binds and Public JavaScript API Methods topic.

Once a connection has been made to a topic, a JSON structure object must be created, which maps JSON field values to database table record values.

The functionality for both the Audit Message Receiver JDBC Delivery Plugin and the Audit Message Receiver Cassandra Delivery Plugin are the same. The following screenshot shows an example message for the Audit Message Receiver JDBC Delivery Plugin receiver:

This business action, Workflow Audit Action (ID = AuditMessaging.WorkflowAuditAction), will automatically be created within your STEP system when the add-on component associated with the Analytics commercial license is installed. The full script is as follows: 

Copy
      // Workflow Audit Action version 1.0. June 2019, Component audit-messaging
// NOTE: A bind must be made to the relevant audit messaging topic for this to produce an audit message, refer to the bottom of 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();

// When using the Audit Message Receiver JDBC Delivery Plugin, the default behaviour when processing 
// messages is to "insert" each message into the database (i.e. create a new database entry for each 
// message). If you wish to "upsert" messages (i.e. if a message with a matching ID exists, update 
// the entry, otherwise create a new database entry), the audit message should contain a field with
// the key "_ID". For example, the field could be set to be a combination of the nodeID and workflowID.
//
// 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);

//--------------- UPDATE BELOW TO YOUR SYSTEM SETUP ---------------
// Send audit message to the audit message framework. A bind will have to be made to a
// topic of an audit message receiver plugin.
//topic.sendMessageAsync(auditMessage)

The topic is configured via the AuditMessaging.JDBCReceiver.TableName setting to map to the table called AUDIT_MESSAGES2.

Note: The application server must be restarted to implement any change to the TableName property.

This external database table is shown in the screenshot below, which shows the view of a database query in a third-party SQL client. For information about this configuration, refer to the Audit Message Framework Configuration Properties and Monitoring topic.

For additional information about mapping JSON field names to database column names in AMF, refer to the Audit Message Framework Database Data Type Mapping topic.