Email Template V1 date format timezone issues - Certification Reassignment

Ok, this seems to come up regulatly, but without a resolution, so I wanted to propose it again, and add some specifics details for it, as well as show some anomalies I am seeing with this in my Ambassador tenant.

First off, details of what I am trying to do:

Email Template: Certification Reassign
Email Template Version: V1

Problem statement: Trying to change $certification.expiration from GMT to another timezone (EST, CST and NZ used for testing)

Known limitations:

Issues present:

  • Unable to convert the timezone from GMT to EST/CST/NZ
  • Discrepancies between test email functionality and actual reassignment usage

During my research, I found that there was a $date variable available, and this works to get the current date when using the TEST EMAIL button.

Here is what I put together for hte body of the email to test with knowing that the $date function worked using the test email.

Dear ${user.name},

${requesterName} has assigned ${numNewIdentities} #if(${numNewIdentities} == 1) user #{else} users #end to you for review in a certification.

Reason for reassignment: ${description}

You have until $spTools.formatDate($certification.expiration,3,0) to review and either approve, change, or revoke access for these users.

TESTING DATES

-----------------------------------

[Base Date Values]
Date: $date
CertExpireDate: $certification.expiration

[Set them to new variables with Velocity]
#set( $varDate = $certification.expiration )
Date: $varDate
#set( $varCertExpDate = $certification.expiration )
CertExpireDate: $varCertExpDate

[Format Base Date with spTools]
#set($formattedDate=$spTools.formatDate($date,"MM/dd/yyyy HH:mm"))
Date: $date
#set($formattedCertExpDate=$spTools.formatDate($certification.expiration,"MM/dd/yyyy HH:mm"))
CertExpireDate: $formattedCertExpDate

[Format Variable Date with spTools]
#set($formattedDate=$spTools.formatDate($varDate,"MM/dd/yyyy HH:mm"))
Date: $date
#set($formattedCertExpDate=$spTools.formatDate($varCertExpDate,"MM/dd/yyyy HH:mm"))
CertExpireDate: $formattedCertExpDate

-----------------------------------

[Format Base Date with velocity dateTool - Direct]

Date: $date.format("yyyy-MM-dd'T'HH:mm:ss", $date, $date.getLocale(), $date.getTimeZone().getTimeZone("NZ"))

CertExpireDate: $certification.expiration.format('yyyy-MM-dd"T"HH:mm:ss', $certification.expiration, $certification.expiration.getLocale(), $certification.expiration.getTimeZone().getTimeZone('NZ') )

[Format Base Date with velocity dateTool - Variable Date]
Date: $varDate.format('yyyy-MM-dd"T"HH:mm:ss', $varDate, $varDate.getLocale(), $varDate.getTimeZone().getTimeZone('CST') )

CertExpireDate: $varCertExpDate.format('yyyy-MM-dd"T"HH:mm:ss', $varCertExpDate, $varCertExpDate.getLocale(), $varCertExpDate.getTimeZone().getTimeZone('NZ') )

Click here to review the certification.

When I test this in my Ambassador tenant using the TEST EMAIL button, I get the following response to my email:


.

If you look at the results, you can see that the $date variable is set to the current time, and if you look at the second arrow, the date is in fact formatted for the correct timezone. You will also notice that the templated items not evaludated show up normally.

Now that I had that, I created a certification to test this with, and then reassigned a certification item to my user so I could test the results using the actual certification details:


.

Now if we look at the email that was received, we see in the first Red arrow that the date is set to the expiration as expected, and in the first Orange arrow, that the variable is set correctly to this same value.
However, if we look at the second Red arrow, we see that using $certification.expiration in place of $date just puts the date calue in line, and does not evaluate it. Additionally, if we look at the second Orange arrow, it does not even evaluate the variable that was set above correctly. Aside from changing the $date value to match the certification expirations, this section is exactly the same, however it is functioning differently using the TEST EMAIL and using the standard functionality.

So my questions that I could use help with are:

  • Is this intended functionality that they should process differently?
  • How can I convert the Timezone from GMT to another timezone in a V1 Template?
1 Like

Links to topics I have referenced:

Thanks for reporting this Geoff. I created a ticket (PLTCORE-4648) for our engineers to look into this. Just a heads up, this will take some time as the owning team has a pretty full backlog, but they will get to it. I will update this topic with any news.

Thanks Colin!

In the mean time, does anyone know of a want to change the timezone for $certification.expiration from GMT to something else (EST/CST) in the Email Template? The client mentioned today that this is important to them for their Access Certification.

Following up on this as it is come to the top of the backlog agaim.

The current workaround idea is to remove the time portion from the email.

@gmilunich - okay…brace yourself!

From testing I realized that, the ‘Test Email’ feature supports v2 variables hence when you send an email via ‘Test Email’ it works fine but when the certification is triggered, it just displays the variable.

As for you to change time zones, use below:

#set($CalendarClass = $spTools.getClass().forName("java.util.Calendar"))
#set($TimeZoneClass = $spTools.getClass().forName("java.util.TimeZone"))
#set($NewCalendarInstance = $CalendarClass.getInstance()) $NewCalendarInstance.setTime($certification.expiration)
#set($GMTTimeZone = $TimeZoneClass.getTimeZone("GMT"))
#set($NZTimeZone = $TimeZoneClass.getTimeZone("Pacific/Auckland"))
#set($offsetCalculation = $NZTimeZone.getRawOffset() - $GMTTimeZone.getRawOffset())
$NewCalendarInstance.add($CalendarClass.getField("MILLISECOND").getInt(null), $offsetCalculation)
#set($CertExpireDate = $spTools.formatDate($NewCalendarInstance.getTime(), "dd-MM-yyyy HH:mm:ss a"))
${CertExpireDate}

All you are doing here is using the offset value from the TimeZone class in java to add/subtract from the GMT offset value which will be ‘0’ and hence giving you the updated time in NZST.

1 Like

I just tested this and it is working enough for what is needed.

For anyone else looking at this, one thing that I noted is that this does not actually change the timezone, but it does modify the time to be correct for the timezone. If you format it with the timezone displayed, it will still show GMT.

I did test changing the timezone using setTimeZone, but that did not change it.

correct, this is just updating the offset value to show correct time… if you also want the timezone to be displayed… this will work →

#set($CalendarClass = $spTools.getClass().forName("java.util.Calendar"))
#set($TimeZoneClass = $spTools.getClass().forName("java.util.TimeZone"))
#set($NewCalendarInstance = $CalendarClass.getInstance()) $NewCalendarInstance.setTime($certification.expiration)
#set($GMTTimeZone = $TimeZoneClass.getTimeZone("GMT"))
#set($NZTimeZone = $TimeZoneClass.getTimeZone("Pacific/Auckland"))
#set($offsetCalculation = $NZTimeZone.getRawOffset() - $GMTTimeZone.getRawOffset())
$NewCalendarInstance.add($CalendarClass.getField("MILLISECOND").getInt(null), $offsetCalculation)
#set($SimplifiedDate = $spTools.getClass().forName("java.text.SimpleDateFormat"))
#set($pattern = $SimplifiedDate.newInstance()) $pattern.applyPattern("dd-MM-yyyy H:mm:ss a z")
$pattern.setTimeZone($NZTimeZone)
#set($rectifiedTimeZoneDisplay = $pattern.format($NewCalendarInstance.getTime())) ${rectifiedTimeZoneDisplay}```

Just wanted to update that this suggestion worked as a workaround for changing the timezone. I did have to make one update, as it did not respect Daylight Savings time. We had to update the $offsetCalculation line to be this:

#set($offsetCalculation = ( $NZTimeZone.getRawOffset() + $NZTimeZone.getDSTSavings()) - $GMTTimeZone.getRawOffset())

With the getRawOffset(), it just got the Standard Time offset for the timezone. The getDSTSavings() is needed to get the time difference between standard and DST for the specified timezone. Once this was updated, it worked as expected for our situation.

It would be nice if this was somehow encapsulated within the existing helper functions, as it is a lot of code to add to the email template for 1 fix.

2 Likes

Thanks @gmilunich , this was a much-needed head start.
I did work on the code a little, as i was seeing some anomalies with the resulting date. Like it was subtracting double the time zones from what i actually needed.

My resulting code is this as I am needing EST/EDT.

#set($CalendarClass = $spTools.getClass().forName("java.util.Calendar"))
#set($TimeZoneClass = $spTools.getClass().forName("java.util.TimeZone"))
#set($NewCalendarInstance = $CalendarClass.getInstance()) $NewCalendarInstance.setTime($certification.expiration)
#set($ESTimeZone = $TimeZoneClass.getTimeZone("US/Eastern"))
#set($SimplifiedDate = $spTools.getClass().forName("java.text.SimpleDateFormat"))
#set($pattern = $SimplifiedDate.newInstance()) $pattern.applyPattern("MM/dd/yyyy h:mm a z")
$pattern.setTimeZone($ESTimeZone)
#set($rectifiedTimeZoneDisplay = $pattern.format($NewCalendarInstance.getTime())) ${rectifiedTimeZoneDisplay}

and when i encapsulte from the first line to just before the ${rectifiedTimeZoneDisplay} in html p’s I am able to keep it as a one liner and not see all the additional lines the template adds

i also used this list to get the needed time zones (What are the Java TimeZone IDs?)

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.