When customizing HTMPL forms, you may find it necessary to include special characters in fields that will be passed to the web interface of Service Desk Manager. As an example, you may put a default "additional where clause" on a contact search that features the wildcard character '%', perhaps to exclude results from some similarly-named groups. As HTMPL is parsed similarly to HTML, many special characters need to be escaped, such as slashes or single quotes within strings; other characters, like '%', have special meaning to the parser and need to be converted to their ASCII equivalents in order to be read properly.
01/06 11:40:38.06 SERVER1 web:local 7464 ERROR session.c 5579 expand_string() failed for name 'ADDITIONAL_WHERE' or value '(sched_start_date%3C=1614927540%20AND%20sched_end_date%3E=1611903600%20AND%20category.sym%20LIKE%20%27CM%%27)%20AND%20(sched_start_date%3C%3D1617343140%20AND%20sched_end_date%3E%3D1614322800%20AND%20category.sym%20LIKE%20%27CM%25%27)'
01/06 11:40:38.06 SERVER1 web:local 7464 ERROR session.c 4027 Error parsing cgi POST string "&ENV_DOCUMENT_ROOT=D:\CA\Service Desk Manager\bopcfg\www\CATALINA_BASE\webapps\CAisd\&ENV_HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64)
In the above example, we see in the highlighted block that there is a double % sequence, ie: %%, which is causing the problem.
addlWhere = "(sched_start_date>0 AND category.sym LIKE 'CM%')";
As seen in the error, the single quote characters are parsed as their ASCII hex equivalent, '%27'. The '%' character, however, is not parsed properly, as '%' is expected to be part of the ASCII equivalent of another character. To work around this limitation, we can intentionally replace '%' with its' ASCII equivalent, '%25' - doing so allows the parser to unambiguously treat the '%25' as if it were just "the character %", which is what we want for this purpose. The additional where clause now looks like the following:
addlWhere = "(sched_start_date>0 AND category.sym LIKE 'CM%25')";