Appian Community and Appian Academy are being upgraded. From July 24–August 3, the Appian Community will be in read-only mode. During this time, the site will be read-only and user registration will be disabled. We apologize for any inconvenience this may cause, but a more secure, stable, and performant Community experience is coming soon!

The new Appian Community launches August 3, followed by Appian Academy on August 7. During the migration, Appian Community Edition, Appian Academy, Documentation, Certifications, Instructor-led Customer Training, Partner Sales Training & Accreditation, and Forum (for Appian Partners and Customers only) will remain available.

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 Children
  • +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]
          }
        )
      )
    )