Using Javascript for accessing advanced operations in Pattern Designer | Optional 



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.

NoteUse 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'.


    • 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
  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.

Article Information

Last Updated:2016-11-28 10:11:29