Home Analyst Portal

How to keep line breaks in announcements?

Tomi_KaartamaTomi_Kaartama Customer IT Monkey ✭
I am creating announcement automatically with the Invoke-Rest method. I am grabbing the contents of the Description field and then using it directly as the body field of the announcement. Unfortunately, all the formatting is lost during the process. 

Any ideas on how to keep the formatting?

Best Answer

  • Tomi_KaartamaTomi_Kaartama Customer IT Monkey ✭
    Accepted Answer
    OK, found the solution. When building they body, you need to use HTML code like this:

    $TestBody = @"
    Two lines<br>
    of body text.<br>


    This is going to give you a JSON body as follows:

    "Body":  "Two lines\u003cbr\u003eof body text.\u003cbr\u003e"

    And this will be displayed properly.

Answers

  • Nicholas_VelichNicholas_Velich Cireson Consultant Ninja IT Monkey ✭✭✭✭
    Hi Tomi,

    I haven't tested this specifically, but there are a few things to try off the top of my head:

    1. Try using the /n, or `n escape characters-- these usually indicate a line break in a string
    2. Try using a line break in HTML, such as the <br> tag

    If the above is going into the contents of an Invoke-RestMethod's URL, they also might need to be encoded to be compatible.

    Thanks,
    Nick
  • Tomi_KaartamaTomi_Kaartama Customer IT Monkey ✭
    Firstly, after JSON conversion, the body text is like this:

    "Body":  "Two linesof body text.",

    This is what I get after I give the invoke-rest command as output. You have the line feeds characters present. 



    However, this is shown on the portal like this:



    Another twist to this is that when you open the annoucement from the "Manage Announcement" list, you very briefly see the text on separate lines but then they are shown on one line only. The text on separate lines is shown for such a brief time that I am unable to take a screenshot.

    Is your suggestion that I should try to replace "" by "`n" after the JSON conversion?



  • Tomi_KaartamaTomi_Kaartama Customer IT Monkey ✭
    Accepted Answer
    OK, found the solution. When building they body, you need to use HTML code like this:

    $TestBody = @"
    Two lines<br>
    of body text.<br>


    This is going to give you a JSON body as follows:

    "Body":  "Two lines\u003cbr\u003eof body text.\u003cbr\u003e"

    And this will be displayed properly.

Sign In or Register to comment.