Sidebar

What is qie.findPreviousMessage? How is it used.

0 votes
428 views
asked May 16, 2016 by brandon-w-8204 (33,270 points)
I see this command in the code wizard? How is it used and what needs to be configured.

1 Answer

+1 vote

qie.findPreviousMessage is used if you ned to lookup previous messages. This command will only work if the following is true:

1. You are setting a messageCache with something that is unique that can be looked up.
2. If the channel is set to persist messageCache values for each message.

 

Here is sample code that can be used in the channel to find the previous message and get a count.

//Set the message cache so this message can be found.
messageCache.setValue('testMessageCache', qie.getMD5Hash(message.getNode('/')));
 
// Create a new paramater map to define the search criteria
var parameters = qie.newParameterMap();
 
// Put in the messageCache name and the value to look for in the message cache.
parameters.put('testMessageCache', qie.getMD5Hash(message.getNode('/')));
 
// Set the current time
var now = qie.formatDate('yyyyMMddHHmmss.SSS', new java.util.Date());
 
//Set the start time 5 minutes earlier than now
var momentAgo = qie.formatDate('yyyyMMddHHmmss.SSS', new java.util.Date(new java.util.Date().getTime() - 300000)); //300000 miliseconds equals 300 seconds or 5 minutes.
 
//Look for previous message.
var previousMessages = qie.findPreviousMessage(parameters, momentAgo, now);
 
//Review how many messages were found.
var messagesFoundCount = previousMessages.size();
 
if (messagesFoundCount > 0) {
   message.setNode('/', 'There was ' + messagesFoundCount + ' previous messages found.');
} else {
   message.setNode('/', 'There was no previous messages found.');
}
 
answered May 16, 2016 by brandon-w-8204 (33,270 points)
edited Jan 29, 2021 by mike-r-7535
...