Notifications

2513 views

Description

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 'test.user@example.com';
      }());
  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('glide.email.username');
  5. No values will be populated.

Workaround

  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 'test.user@example.com';})(); 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 'test.user@example.com';})();
  • 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);
           a.get(c);
        }
    }
    return a;
};

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

As an example

  • INCORRECT: javascript: current.caller_id.email
  • CORRECT: javascript: ClientTemplateContext.getCurrent().caller_id.email

Related Problem: PRB1321771

Seen In

There is no data to report.

Intended Fix Version

New York

Fixed In

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

Safe Harbor Statement

This "Intended Fix Version" information is meant to outline ServiceNow's general product direction and should not be relied upon in making a purchasing decision. The information provided here is for information purposes only and may not be incorporated into any contract. It is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. The development, release, and timing of any features or functionality described for our products remains at ServiceNow's sole discretion.

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2019-06-27 05:49:05
Published:2019-01-31