Skip to main content
New Participant
Jun 9, 2022 9:05 AM UTC
Solved

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

    mikes0011
    mikes0011Answer
    Brainy
    Jun 9, 2022 3:55 PM UTC

    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 "" */
        ""
      },
      
      reduce(
        fn!substitute,
        trim(ri!input),
        a!forEach(
          local!characters,
          {
            fv!item,
            local!replacements[fv!index]
          }
        )
      )
    )

    The Expression Guru

    2 replies

    agamb0001
    Participating Frequently
    Jun 9, 2022 9:22 AM UTC

    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.

    [View:https://www.w3schools.com/html/html_entities.asp]

    Hope it helps !

    mikes0011
    mikes0011Answer
    Brainy
    Jun 9, 2022 3:55 PM UTC

    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 "" */
        ""
      },
      
      reduce(
        fn!substitute,
        trim(ri!input),
        a!forEach(
          local!characters,
          {
            fv!item,
            local!replacements[fv!index]
          }
        )
      )
    )

    The Expression Guru