Performing scripted evaluation of the to, cc, bcc, from, and reply-to values in email client template or email client does not execute correctly. In some cases, it will display "Invalid function definition"

Steps to Reproduce

  1. Define an Email Client Template with the following values:
    • Table: incident
    • Any one of To, Cc, Bcc, Reply to, From (London and Kingston) fields:
      javascript: (function() {
      return '';
  2. Open the Email Client from an active incident
  3. An error message "Invalid function definition" is displayed
  4. Alternately, add the following script to the To, Cc, Bcc, Reply to, From fields
    javascript: gs.getProperty('');
  5. No values will be populated.


  1. Hard-code the email address in the email client template or manually update this field as required.
  2. If a javascript: tag needs to be used, please define the functions in a "Script Include" with the Client Callable option selected. Then, execute the function from the script include instead.

In more detail,

String fields with "javascript:" tags, are executed in a sandboxed script context for the to,cc,bcc, reply_to and from fields.

To allow the function in the script to be executed, you need to define them in a "Script Include" with the Client Callable option selected. Then, execute the script on the sandboxed script context area.

For example, a To value of: javascript: (function() { return '';})(); can be moved to a Script include

For this workaround example, a Script include named "TestScriptInclude" was created and the function was put into the Script Include function "getTo". The new To value in the template could be: javascript: new TestScriptInclude().getTo();

  • Incorrect: javascript: (function() { return '';})();
  • Correct:   javascript: new TestScriptInclude().getTo();

Note: The "current" object (Email Client target record) is not accessible in the script context, but it is possible to determine the target record using URL parameters in a script include.

How to retrieve the current object workaround

Create a Script Include named "ClientTemplateContext" with the Client Callable option selected, copy and paste the following script in:

// This class will create a function ClientTemplateContext.getCurrent, 
// that will retrive the current record from the URL sysparm_table and sysparm_sys_id parameters.
var ClientTemplateContext = Class.create();
ClientTemplateContext.getCurrent = function() {
    var b = GlideTransaction.get().getRequestParameter("sysparm_table"),
    c = GlideTransaction.get().getRequestParameter("sysparm_sys_id"),
    a = null;
    if (b)
        if (c) {
           a = new GlideRecord(b);
    return a;

Any references to "current" in a client template can be replaced with ClientTemplateContext.getCurrent()

As an example

  • INCORRECT: javascript:
  • CORRECT: javascript: ClientTemplateContext.getCurrent()

Related Problem: PRB1321771

Seen In

There is no data to report.

Fixed In

Kingston Patch 13
London Patch 5
London Patch 6
Madrid Patch 1
New York

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2019-06-27 05:49:05