DOCX from Dynamic Template Error with "<"

Hi All, I am generating a document using DOCX from dynamic template smart service but the document is not generating, error says that one of the field consists of "<" symbol. When I removed the symbol then it works. Could anyone please suggest if "<" symbol is supported in docx from dynamic template smart services.

Thank You

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Hi

    You could substitute the "<" symbol with "& l t ;" (remove the spaces) using substitute function in your data before you send it in the Dynamic Template smart service.

    I would suggest to create a rule for general / commonly used HTML entities. You can find related replacement codes here.

    Hope it helps !

  • +1
    Certified Lead Developer

    Plaintext MUST be sanitized before being passed into the Docx Generator node(s), which they don't warn you about (since un-sanitized greater-than, less-than, and ampersand symbols *will BREAK* the generated word file).  I tend to encapsulate the following logic into an expression rule which will then be used to sanitize any text (at least any where there's any variability beyond what you're sure will be safe).

    /*  RULE_wordDocxParagraphFormatter  */
    
    a!localVariables(
      local!characters: {
        "&",
        ">",
        "<",
        char(10),
        char(13)
      }, /* NOTE: the ordering of these is important. */
    
      local!replacements: {
        tohtml("&"),
        tohtml(">"),
        tohtml("<"),
        rule!RULE_insertWordLineBreak(),  /* returns "</w:t><w:br/><w:t>" */
        ""
      },
      
      reduce(
        fn!substitute,
        trim(ri!input),
        a!forEach(
          local!characters,
          {
            fv!item,
            local!replacements[fv!index]
          }
        )
      )
    )