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

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

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

Children
No Data