ALERT: Some images may not load properly within the Knowledge Base Article. If you see a broken image, please right-click and select 'Open image in a new tab'. We apologize for this inconvenience.

AHD04400 Argument Error due to special characters in HTMPL and JavaScript forms

book

Article ID: 111907

calendar_today

Updated On:

Products

CA Service Management - Asset Portfolio Management CA Service Management - Service Desk Manager

Issue/Introduction

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.

Cause

Under such conditions in which such characters such as "%" are improperly placed in the htmpl and javascript files, you may experience an AHD04400 Argument Error and in the stdlogs, you may see an error such as:

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.

Environment

Release:
Component: USRD

Resolution

Continuing our example above, let's assume that we are adding the additional clause as follows, as seen in the custom schedule_chg.js (Javascript for the Change Calendar):

addlWhere = "(sched_start_date>0 AND category.sym LIKE 'CM%')";

This clause, if manually run through the change order search page (list_chg.htmpl), will process for entries where the category starts with "CM". However, as HTMPL and javascript is parsing treats the '%' specially, this same clause will yield an error if inserted directly into the HTMPL and javascript form as seen above.

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')";

Additional Information

If you encounter similar errors with other special characters, you may need to replace them with their equivalent ASCII hex codes within your HTMPL forms. Consult an ASCII character table to locate your special character, and replace it with the equivalent hex code as listed, preceded by a '%' character. An example ASCII character table is linked below.
https://en.wikipedia.org/wiki/ASCII#Printable_characters