How to retain line breaks when sending placeholders in HTML formatted emails

Version 7

    Verified Product Versions

    LANDESK Service Desk 7.6LANDESK Service Desk 7.7.xLANDESK Service Desk 2016.x

    Problem

    When sending emails from Service Desk such as an Assignment or Reminder you want to reference some text from a mult-line attribute such as some note text or the description of an incident via a placeholder.  However, if you hvae the option Send mail as HTML enabled in the Outbound Mail Server Settings then all the text from the placeholder will appear on a single line on the resutling email.

     

    Cause

    This occurs because the email is sent in HTML format.  In HTML a line break is explicitly specified through the <BR /> HTML tag and any new lines in the code itself are ignored.

     

    Solution One - Using <PRE> tags (when NOT using a HTML enabled field for the notification body)

    If you are sending an Assignment or Reminder and the Details attribute is NOT enabled for HTML then you can manually enter HTML code to achieve any formatting.  This is also the case when configuring escalation notifications for a Response Level.  One HTML tag is <PRE> which forces the text within it to be formatted with a fixed width font and mroe importantly to interpret line breaks in the text.

     

    An example of how to use this within a Reminder is as follows:

     

    A new note has been added to incident {Id}: <BR /> <BR /> Note Summary: {Notes/Title} <BR /> Note Details: <BR /> <PRE>{Notes/Text}</PRE>

     

    The use of the <BR /> tags is to add line breaks where they would otherwise be ignored.  One byproduct of this is that the text will appear using a fixed width font (the same as the HTML code example given above in this document appears).  If you would prefer not to do this you can use the next solution.

     

    Solution Two - Using a calculation to add <BR /> tags (when using a HTML field for the notification body)

    If you are sending an Assignment or Reminder and the Details attribute IS enabled for HTML then you cannot manually add the HTML code to use a <PRE> tag.  However you can use a new calculation attribute which manipulates the text adding <BR /> tags for each line break.  You can then reference this attribute in placeholders as required.  Belwo are the steps to implement this for the Text attribute on the Note object.

     

    1. Within Object Designer create a new String attribute with length -1 on the same object as the attribute you want to reference - in this example the Note object.

    2. Set the Calculation Type to Before Save - this will automatically open the Calculation Editor.

    3. Use the following calculation formula, replacing the reference to Note.Text to match the attribute you are copying from:

     

    Value = Note.Text return Value.Replace('\n', '\n<BR /> ')

     

    4. Ensure the name of the attribute being copied from appears in the Dependencies panel, in this case Text.

    5. Press OK and save the object.

     

    From now on in any place you reference the attribute via a placeholder modify this to use the new attribute.  For example instaed of referencing {Notes/Text} reference {Notes/_YourNewAttribute}.

     

    Performing the opposite

    If you want to strip HTML code when referencing a HTML attribute in a placeholder for use on a plain text notification see the following document: How to get the plain text value from a HTML enabled attribute as a placeholder

     

    Environment

    Service Desk version 7.3 onwards.