How to get the plain text value from a HTML enabled attribute as a placeholder

Version 7

    Verified Product Versions

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

    Updated 2016/11/24

    The calculation has been updated to use the .NET 4 System.Net WebUtility to encode the HTML string.

    Also, the regular expressions haven been updated to preserve newlines.


    Currently, when you reference an HTML enabled attribute in a placeholder, the full HTML code is returned.  While this is useful in the outbound email notification that wants the original formatting and embedded images, there is no obvious way to get a plain text version of the value.



    The solution to this is to create a new calculation attribute which manipulates the code from the HTML enabled attribute and saves it as a separate plain text version.  You can then reference this attribute instead for placeholders where required.  Below are the steps to implement this, in this example we'll assume the Text attribute on the Note object within Incident Management is HTML enabled and we want a plain text version of its data:


    1. Within Object Designer create a new String attribute with length -1 on the same object as the HTML enabled attribute - in this example on the Note object.

    2. Set the Calculation Type to BeforeSave.  This will automatically open the Calculation Editor.

    3. Use the following code for the calculation, replacing the reference to Note.Text in the first line to the name of the HTML enabled attribute:


    import System
    static def GetAttributeValue(Note):
      // Storing Note HTML text in Variable for follwoing conversion
      Value = Note.Text
      // Replacing </br> and </p> with newlines to preserve parts of the formatting
      Value = System.Text.RegularExpressions.Regex.Replace(Value, """<br\s*/?\s*>""", "\r\n")  
      Value = System.Text.RegularExpressions.Regex.Replace(Value, """</\s*p\s*>""", "\r\n")  
      // replacing all remaining HTML tags
      Value = System.Text.RegularExpressions.Regex.Replace(Value, """<[^>]*>""", "")  
      // decoding HTML-encoded parts of the string
      Value = System.Net.WebUtility.HtmlDecode(Value)
      return Value


    4. Ensure the name of the HTML enabled attribute is listed in the Dependencies panel, in this case: Text.

    5. Press OK and then save the object.


    From now on anytime the HTML enabled attribute data is created or modified the calculation attribute will be updated, and any placeholders to {Notes/Text} can be replaced with {Notes/_YourNewAttribute}.


    Performing the opposite

    If you want to use a plain text attribute in an HTML formatted email and need to retain line breaks, please see the following document: How to retain line breaks when sending placeholders in HTML formatted emails.



    Service Desk 7.3 onwards