Code Editor

Use the Code Editor to simplify the process of writing scripts in ScriptRunner. The browser-based Code Editor provides completions and parameter assistance using four simple keyboard shortcuts.

  • Completions - Press Ctrl+space to complete the current class, method, property or variable.

  • Smart completions - Press Ctrl+shift+space to complete the method, property or variable, respecting the expected type.

  • Parameter hints - Press Ctrl+p when inside method parameters to show the possible parameter types for a method.

Completions

Press Ctrl+space to display a list of suggestions based on what is written in the Code Editor. Select a completion or continue typing, suggested completions narrow down as more is typed.

Example

A simple condition is being added that allows the transition only if the issue has been reported by the user with key: admin.

The variable issue is commonly passed in the script binding.

Click the question mark icon below the script to see binding variables.

Pressing Ctrl+space shows a list of possible completions. The text to the right of the suggestions shows the type of the property or return type of the method.

Select one of the suggested completions or continue typing, the suggestions narrow down as you type. Alternatively, type part of a method or property, for example issue.getP, then press Ctrl+space.

To save typing, use camel case abbreviations. For example, to get a CustomField instance from CustomFieldManager using getCustomFieldObjectsByName, type getCFOBN, or getCusFiObj to display getCustomFieldObjectsByName.

Text within parentheses shows the types for any expected arguments. Sometimes there may be multiple methods with the same name, but with different types of parameters. For example, obtain a CustomField instance using its numeric ID, or its string ID:

Completions also work for classes. Most standalone scripts require a ComponentAccessor or ComponentLocator, but it’s hard to remember the class name for the import. To save time, enter a part of the class name, using camel case abbreviations if required, and press Ctrl+space.

Upon selecting the class, the import line is added automatically.

Smart Completions

Press Ctrl+shift+space to display suggestions as above, suggesting only the types applicable to the current context. Type to see a list of smart completions matching the type of the preceding input.

Example

In the following script, regular completions would suggest the dog and duck variables. However, Smart Completions only shows the string dog and not the integer duck. This is because only dog matches the "cat" type (string). Smart completions suggests only other string types, as that is the expected type based on the preceding input.

dump() also returns a string, so it is valid in this context.

Similarly, in the following example, Smart Completions only shows variables or methods that fit the parameters of the method used.

Parameters

When typing method parameters, it is easy to forget the expected types. The Code Editor displays all possible parameter types applicable. Press Ctrl+p to show possible options based on the text entered in the Code Editor.

Bold items indicate the parameter being entered or edited. Greyed out items are methods that are incompatible with the parameters typed.

On this page