Issue - MS Word 2007 Doc from Template

Hi,

I am trying to generate a word document using "MS Word 2007 Doc from Template".

The element which I am passing to a process model is having data like "Test & 1234". When I try to generate the document with this value, it is throwing an error when I try to open the generated document.

Where as if I updated the value with "Test1234" and generate the document, I was able to open the word document without any issues.

Any advises please.

Let me know if you want any further details.

  Discussion posts and replies are publicly visible

Parents Reply
  • +1
    Certified Lead Developer
    in reply to Rao2022

    You beat me to it, lol - yes, a long time ago I developed the following expression rule that all un-sanitized text should be passed through when using this smart service.  Note this is only really needed when the incoming text will be variable (i.e. where there's a possibility that special characters will sneak in).  This is what I still use now.

    /* Expression Rule i.e. APP_UTIL_sanitizeTextForWordDocx */
    
    a!localVariables(
      local!characters: {
        "&",
        ">",
        "<",
        char(10),
        char(13)
      }, /* the ordering of these is important. */
    
      local!replacements: {
        tohtml("&"),
        tohtml(">"),
        tohtml("<"),
        </w:t><w:br/> <w:t>,  /* inserts a Word linebreak */
        ""
      },
    
      reduce(
        fn!substitute,
        trim(ri!input),
        a!forEach(
          local!characters,
          {
            fv!item,
            local!replacements[fv!index]
          }
        )
      )
    )

Children
No Data