IBM Security QRadar SOAR

 View Only
Expand all | Collapse all

TIPS : Line break with Python3 scripts

  • 1.  TIPS : Line break with Python3 scripts

    Posted Thu January 28, 2021 05:28 AM
    When we were writing Strings using Python2 in Resilient Script, "\n" can be used to add a line break.
    But in the case of Python3 I found that there're no effects with "\n" and "<br>" is usable. 
    [Python2]
    incident.addNote("Hello\nPython")
    >> Hello
    >> Python


    [Python3]
    incident.addNote("Hello" + "<br>" + "Python")
    >> Hello
    >> Python​


    It took me about 30 minutes to resolve this, so I'll share it to un-experienced developers.

    ------------------------------
    YUSUKE TOYAMA
    ------------------------------


  • 2.  RE: TIPS : Line break with Python3 scripts

    Posted Fri January 29, 2021 06:39 AM
    Hi Yusuke,

    Thanks for your post. What you see here is that in Python 3, the default format for a text area field like a Note is HTML. This is why <br> works as a line break but \n does not.

    If you want to use \n as a line break, you can change the text format to plain text like so:
    incident.addNote(helper.createPlainText("Hello\nPython"))

    We will be updating the documentation in version 40 with a complete list of differences between Python 2 & 3 in Resilient such as this one. Keep an eye out for updates to this section Python 2 and Python 3 differences

    Thanks,

    ------------------------------
    Sean Mc Cann
    ------------------------------