Most Recent

Blog Post

Including a timestamp in a Pega Correspondence

Including a timestamp in a Pega Correspondence

Pega CRM allows for flexible and accurate communications towards your customers. In general each Correspondence rule functions as a template and contains a set of property references to render dynamic case values. This is similar to the purpose of fields in Microsoft Word; yet more powerful since properties can contain any computed result value. Such Correspondences can also include other Correspondence and Fragment rules to insert blocks of dynamic texts.

Creation Date/Time

One particular use case which I´ve encountered during one of my Pega projects is the need for rendering the current date into a PDF or email communication. While it is perfectly possible to set some property with the system date on the Clipboard beforehand, we approached this a little differently as is described in this article.

Remark: Please note that simply including .pxCreationDateTime or .pxUpdateDateTime actually contains the timestamp of the current case instance and not the time you generated your correspondence.

Because we do not want to pollute the Clipboard with some temporary property and the actual .pxCreationDateTime for the Link-Attachment or Data-Attachment object only become available after generating the correspondence I´ve written two rules that solve this problem.

Correspondence or Fragment

To generate a date-stamp for the current system date (given local time) without the need for an explicit property on the Clipboard like pxCreateDateTime you could define a Correspondence or Fragment with the following JavaServer Pages (JSP) source code:

<%
String format = tools.getParamValue("Format");
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd MMMM yyyy");//Default formatting
Date dateUTC = new Date();//JRE system timestamp in UTC i.e. Thu Mar 22 08:43:36 UTC 2018
StringBuffer strLocal = new StringBuffer();
if (format.length() > 0) {
	formatter = new java.text.SimpleDateFormat(format);
	strLocal.append(formatter.format(dateUTC));//Java date formatter
} else {
	String strTimeZone = 	tools.findPage("pxRequestor").getString(".pyUseTimeZone");//Fetch timezone from pxRequestor system page
	strLocal.append(PRDateFormat.format(null, strTimeZone, PRDateFormat.DEFAULT_DATE_LONG, dateUTC));//Pega date formatter
}

tools.putSaveValue("result", strLocal.toString());//Save the value into symbolic $save (which you cannot format afterwards)

%><pega:reference name="$save(result)"/>

Pega Correspondence Fragment

Use the above definition by including this rule in your Correspondence like:

<pega:include name="CurrentDate.Mail" type="Rule-Corr-Fragment"></pega:include>

However, Correpondence and Fragment rules do not allow parameters to implement support for a output formatting. This is where a read-only Control rule could help out.

Control with Formatting

You could also use a Control rule to render a timestamp. The benefit of this rule type is that it supports the use of parameters. In the next example, I´ve leverage this by adding a formatting input parameter to customize the way the timestamp will be formatted:

<%
String format = tools.getParamValue("Format");
java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("dd MMMM yyyy HH:mm:ss");//Default formatting
Date dateUTC = new Date();//JRE system timestamp in UTC i.e. Thu Mar 22 08:43:36 UTC 2018
/*DateTimeUtils dtu = ThreadContainer.get().getDateTimeUtils();
String timestampGMT = dtu.getCurrentTimeStamp();//Alternatively using Pega method for retrieving the system timestamp in GMT
dateUTC = dtu.parseDateTimeString(timestampGMT);*/
StringBuffer strLocal = new StringBuffer();
if (format.length() > 0) {
	formatter = new java.text.SimpleDateFormat(format);
	strLocal.append(formatter.format(dateUTC));//Java date formatter
} else {
	String strTimeZone = tools.findPage("pxRequestor").getString(".pyUseTimeZone");//Fetch timezone from pxRequestor system page
	strLocal.append(PRDateFormat.format(null, strTimeZone, PRDateFormat.DEFAULT_DATE_LONG, dateUTC));//Pega date formatter
}

tools.putSaveValue("result", strLocal.toString());//Save the value into symbolic $save (which you cannot format afterwards)

%><pega:reference name="$save(result)"/>

Pega Control Source

Add this Control rule as formatter to some placeholder reference property in your Correspondence like:

<pega:reference name=".pyDateTimeValue" format="CurrentTimestamp">
	<pega:param name="Format" value="dd MMMM yyyy HH:mm:ss"/>
</pega:reference>

Alternative Solution

Finally, in context of a Flow in Pega one could also consider using a simple parameter lookup of TimeFlowStarted as long as PRPC offers this timestamp:

<%
String started = tools.getParamValue("TimeFlowStarted");
tools.appendString(started);
%>

Have a nice weekend!

[Edgar] (3/23/2018 9:52:04 AM)

 

Twitter Feed

@edgarverburg

Bio

About Edgar

Edgar is a software engineer with experience in TIBCO Middleware and Pega Case Managemement. He holds a master's degree in Computer Science with a specialization in Data Visualization & Computer Graphics.

In his spare time Edgar reads SOS and Empire, mixes house music, blogs and writes film reviews or goes running.


Currently employed by SynTouch he is specifically looking for a PRPC project. Feel free to contact him for challenging assignments through LinkedIn.