KB Article #180297

Add timestamp to a message attribute

Problem

You need to add timestamps to a message.

Resolution

This can be done by using a Groovy script in a Scripting Language filter and the code sample below. This script adds the current system time to a message attribute called session.timestamp which can then be used by other filters or messages.


import java.sql.Timestamp;
import java.util.Date;

def invoke(msg) {
    Date date= new Date();
    long time = date.getTime();
    Timestamp ts = new Timestamp(time);
    msg.put("session.timestamp", ts.toString());
    return true;
}