Skip to main content
January 31, 2022
Solved

array to text

  • January 31, 2022
  • 8 replies
  • 0 views

Team,

I have below code :

a!localVariables(
local!data1:{"test1<br>","test2<br>"},
local!data1
)

Output is list of text strings

  • "test1<br>"(Text)
    • "test2<br>"(Text)

    I want the output to be in format "tetst1<br>test2<br>"

    Basically i am formatting a data before sending into email template but it is appearing like below , i want the semicolon to be removed.

    Test1
    ; Test2

    It should be like below

    Test1
    Test2

    ANy suggestions ?

      Best answer by mikes0011

      a!localVariables(
        local!data1:{"test1
      ", "test2
      "}, joinArray(local!data1, char(10)) )

      will result in:

      test1<br>
      test2<br>

      To get rid of the HTML break tags you will need to do a subsequent line-by-line command such as stripHtml(), though I don't presume to know exactly what you're hoping to have happen with HTML formatting in your input text.  FYI appian won't format HTML as rich text without some pretty significant user-defined parsing, etc, which gets pretty complicated to set up.

      8 replies

      mikes0011
      mikes0011Answer
      Brainy
      January 31, 2022

      a!localVariables(
        local!data1:{"test1
      ", "test2
      "}, joinArray(local!data1, char(10)) )

      will result in:

      test1<br>
      test2<br>

      To get rid of the HTML break tags you will need to do a subsequent line-by-line command such as stripHtml(), though I don't presume to know exactly what you're hoping to have happen with HTML formatting in your input text.  FYI appian won't format HTML as rich text without some pretty significant user-defined parsing, etc, which gets pretty complicated to set up.

      The Expression Guru
      January 31, 2022

      Thank you , It worked.

      stewart.burchell
      January 31, 2022

      In answer to your first question you can use fn!joinarray():

      fn!joinarray(
        a!localVariables(
          local!data1: { "test1
      ", "test2
      " }, local!data1 ) )

      If you want to have the output actually on separate lines (as is indicated by your second question) then you can loop through your input items and append a "new line" Unicode character to all items except the last item:

      a!localVariables(
        local!myList: { "Test1", "Test 2", "Test 3" },
        local!myResult: fn!joinarray(
          a!forEach(
            items: local!myList,
            expression: if(
              fv!isLast,
              fv!item,
              concat(fv!item, char(10))
            )
          )
        ),
        { a!paragraphField(value: local!myResult) }
      )

      mikes0011
      Brainy
      January 31, 2022

      Maybe it's just me, but this seems like a lot of extra run-around compared to `joinarray(local!list, char(10))` which is equivalent.

      The Expression Guru
      stewart.burchell
      January 31, 2022

      You'll get an extra char(10) in your code, which, in the scheme of things, may not be a big deal. I was trying to provide illustrations, not definitive solutions.