How to limit a DateTime placeholder for email or a Web Access report template

Version 6

    Verified Product Versions

    LANDESK Service Desk 7.7.xLANDESK Service Desk 7.8.xLANDESK Service Desk 2016.xLANDESK Asset Central 2016.x

    By default when a DateTIme attribute is evaluated to a placeholder for use in an email or in a report template for a Web Access query the format will be as follows:

     

    08/06/2011 13:48:08 [GMT Daylight Time (GMT+01:00)]

     

    If you don't want to show the timezone or just show the date, this can be achieved using the technique described in the following document: How to limit the number of characters returned by a placeholder.  However this carries two very crucial limitations:

     

    1. The text will be suffixed "..." to denote that there was text truncated.  For the above example {CreationDate:13} evaluates to 08/06/2011...
    2. On Service Desk versions prior to 7.5 the value will no longer be adjusted for your local timezone.  For the above example {CreationDate:22} evaluates to 08/06/2011 12:48:08... which is the time in UTC rather than GMT Daylight Time as you would expect.  If you are located outside of the UK this will make a drastic difference in the resulting value.

     

    Working around the limitations

    The only way to work around the two limitations caused by truncating the placeholder is to avoid having to use the truncation feature.  Instead you can use a new calculated attribute to store the DateTime in a format of your choice as a String and refer to this attribute in your placeholders instead of the DateTime itself.  Note that Service Desk version 7.3 or higher is required for this.

     

    1. Within Object Designer view the object your DateTime attribute is on and create a new String attribute with length 100.

    2. Set the Calculation Type to Before Save.

    3. Set the calculation formula as follows, replacing Incident.CreationDate to the appropriate DateTime attribute you want to reference:

     

    Value = Incident.CreationDate.ToLocalTime().ToString()
    return Value
    

     

    4. Ensure that the DateTime attribute you're referencing is also listed in the Dependencies panel.  If it does not appear automatically you can enter this manually.

    5. Save the attribute and use this for your placeholders instead of the DateTime attribute.

     

    Note: Using a Before Save calculation type means the calculation will be triggered whenever the source DateTime attribute is set or modified.  However upon the calculation attribute's creation it will not retrospectively set itself for existing records.  To do this you can change the calculation type to Scheduled and create a one-off run in Schedule Manager to set the existing records, then change the type back to Before Save.

     

    Changing the format

    The above example will use the same format as the original DateTime placeholder except it will remove the timezone suffix.  If you want to also remove the time, or change the format in another way, you can do this by using format specifiers in the ToString() method of the calculation formula.

     

    The following calculation will return just the date:

     

    Value = Incident.CreationDate.ToLocalTime().ToString("dd/MM/yyyy")
    return Value
    

     

    For more information on using date specifiers plus a link to the Microsoft article that lists all available options please see the section Formatting a DateTime attribute in a String Attribute in the document: Using dates, times and time spans in Calculations.