Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Using Javascript for accessing advanced operations in Pattern Designer - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Using Javascript for accessing advanced operations in Pattern Designer
KB0597728

Using Javascript for accessing advanced operations in Pattern Designer


4968 Views Last updated : Sep 3, 2024 public Copy Permalink
KB Summary by Now Assist

Issue

Using Javascript for accessing advanced operations in Pattern Designer | Optional 

 

Overview

This article is relevant for the Geneva and later releases.

You can create or customize patterns using Pattern Designer. The Pattern Designer user interface allows you to use only predefined operations. However, you can also use Javascript to use advanced operations that are not part of the Pattern Designer UI. Insert Javascript to access predefined context (CTX) objects to run commands, retrieve attributes values, or set attribute values. This feature is available for the Set variable and Transform table operations.

Note: Use Javascript in Pattern Designer only if you are an advanced user with programming experience.

 

Execution context methods
There are several execution methods of the CTX objects in Pattern Designer:
  • getCommandManager(): This method returns a Command Manager object (see details on this object below).
  • getAttribute(name): This method uses the attribute name as its input and returns its value. If the attribute is scalar, it returns an object of String type. If it is a table, it returns a Java object of the List type <Map<String,String>. Each object in the List is a row in the table. Each row is Map<String,String>, where the key is the column name and the value is the field value.
  • setAttribute(name, Object):This method sets an attribute in the context. The first argument is the attribute name. The second can be a String, in case of scalar attribute, or Java object of type List<Map<String,String>>, in case of table attribute.
  • CommandManager.shellCommand: This method executes a command on a target host. On UNIX machines or network devices, this command is using SSH. On Windows machines, it runs commands using the 'cmd'.

    Arguments:

    • Command: string containing the command to be executed
    • superUser: Boolean argument defining if the command needs to be executed with elevated rights like sudo
    • executionMode: put null here
    • commandParams: put null here
    • executionContext: put CTX here
Procedure
  1. Create a new pattern or select an existing pattern to customize as described in the product documentation.
  2. Navigate to the Identification section or Connection section.
  3. Add a new step or select a step you want to customize.
  4. Select Set Variable from the Operation list.
  5. In the Value field, type EVAL(javascript:), and then click the Edit Text button.

  6. In the Edit Text window, enter your Javascript code.
    For example, enter eval(javascript: CTX.getCommandManager().shellCommand("hostname", false, null, null, CTX);) to execute the hostname comment on the target host.
  7. Click OK.
    The Javascript is displayed in the Value field. 
  8. Enter the relevant entry that in the Parameter field.
    The parameter displays the value that is retrieved as a result of running the Javascript.
  9. Click Save.

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.