Skip to main content
June 30, 2021
Solved

How i can substitute the ";" for " " , because already tried with substitute() and i can't do anything

  • June 30, 2021
  • 7 replies
  • 0 views

For example I made a process where I send an email that already has an html template and replace the input with a dictionary with data to be sent. But when it is sent my table that is in the template gets ";" over the table as I'm going to show you here.

Someone knows why he put the ";"

Best answer by mikes0011

Substitute() will only work for characters actually contained within your text.  In this case, your text presumably doesn't contain the ";" character itself, as this is inserted automatically by Appian whenever rendering an array into plaintext.  I'm not sure what your current code is so it's hard to guess at exactly what the best solution might be, but you will probably want to use a looping function or at least something that specifically deals with arrays. 

The easiest is "joinArray()", which allows you to automatically concat together all items in the passed-in array, separated by whatever character you designate.

joinArray(
  pv!myCdtArray.description,
  " "
)

For more advanced use cases, you should iterate over the array using a!forEach(), as this allows you to do item-by-item processing when necessary.

a!forEach(
  items: pv!myCdtArray,
  expression: fv!item.description & if(fv!isLast, null(), " ")
)
/* the above is functionally identical to joinArray(), but is easy to expand to handle other use cases which joinArray() cannot */

7 replies

shikhat
June 30, 2021

Hi Tiago,

Can you please let us know how send email node is configured?  Are you displaying any data above your table in the Email (HTML) template ?

June 30, 2021

I dont have more data than this : , and the node i just have : =

a!forEach(
  items: rule!P2P_sandBoxTiago(),
  expression: "<tr>" & "<td>" & fv!item.processId & "</td>" & "<td>" & fv!item.typeOfRequest & "</td>" & "<td>" & fv!item.requester & "</td>" & "<td>" & fv!item.createdOn & "</td>" & "<td>" & fv!item.description & "</td>" & "<td>" & fv!item.type & "</td>" & "</tr>"
)

csteward
June 30, 2021

Mike's suggestion is correct here, you will want to joinarray() around the forEach() building your HTML for the email.

joinarray(
    a!forEach(
      items: rule!P2P_sandBoxTiago(),
      expression: "" & "" & fv!item.processId & "" & "" & fv!item.typeOfRequest & "" & "" & fv!item.requester & "" & "" & fv!item.createdOn & "" & "" & fv!item.description & "" & "" & fv!item.type & "" & ""
    ),
    ""
)

mikes0011
mikes0011Answer
Brainy
June 30, 2021

Substitute() will only work for characters actually contained within your text.  In this case, your text presumably doesn't contain the ";" character itself, as this is inserted automatically by Appian whenever rendering an array into plaintext.  I'm not sure what your current code is so it's hard to guess at exactly what the best solution might be, but you will probably want to use a looping function or at least something that specifically deals with arrays. 

The easiest is "joinArray()", which allows you to automatically concat together all items in the passed-in array, separated by whatever character you designate.

joinArray(
  pv!myCdtArray.description,
  " "
)

For more advanced use cases, you should iterate over the array using a!forEach(), as this allows you to do item-by-item processing when necessary.

a!forEach(
  items: pv!myCdtArray,
  expression: fv!item.description & if(fv!isLast, null(), " ")
)
/* the above is functionally identical to joinArray(), but is easy to expand to handle other use cases which joinArray() cannot */

The Expression Guru
June 30, 2021

Thanks! It worked

mikes0011
Brainy
June 30, 2021

Cool, thanks for confirming.

As a tag-on note, this is a good example of where it can be tremendously helpful to create a new Expression Rule to generate your desired output text, simply give it a rule input of your data type (array) and pass that in from the process model.  Then in the Expression Rule Editor you can generate test data (either with a query or manually) and get an instant preview of what the generated text / HTML / etc will look like.  The added benefit of this method is, if you ever need to make updates, you can just update the expression rule instead of having to make Process Model edits - and the change will take effect immediately (even for running instances of the process model).

The Expression Guru