JavaScript editor

The JavaScript editor helps to write complex code calculations in Medallia Experience Cloud when using JavaScript. The editor provides several tasks to ease working with the following:

For example, to access the editor for a K-field's calculation, select a specific K-field and click the Edit JavaScript below the Calculation text box.

Calculation text box.

The editor window splits into 3 panes:
  • The canvas — This is where you write the actual code. The canvas is more helpful for writing code than the field where you would otherwise write the code manually. It offers the following:
    • Syntax highlighting and automatic indentation.

    • Inlined warnings and errors appear on the side of your code without needing to run it.

    • Helper shortcuts.

    • Code quick tests.

  • Flow pane — This is where the code is executed.

  • Documentation pane — Function documentation.

Editor window divided into three panes.

Close the editor at any time by pressing the Esc key.

Auto-complete helper shortcuts

Add Functions, Methods, Fields and Nodes in JavaScript.

Control + Space opens a dialog showing what functions, methods, fields and nodes are available, and where you can select one to add it to the code. Use this shortcut after starting to type a word or keep typing once the dialog is open to filter the displayed options.

Before placing a function, select it on the dropdown to view a brief description, required inputs and examples:

Auto-complete helper for functions.

Before placing a field, select in on the dropdown to see the values its Alternative set can take. Note that this may not be available for some alternative sets.

Auto-complete helper for fields.

The autocompletion is context-sensitive of where the shortcut is used, so only shows options that apply to it. The example below calls the helper after typing cube., so the helper only displays the methods that can be called from the slug cube object.

Calling a helper after typing an object only show the methods applicable to that object.

Auto-complete helper is available in the following editors:
  • K-field — For functions and fields.

  • R-field — For functions and fields.

    Tip: To see the available cube functions, type cube. in the R-field editor, then click Control + Space.
  • Auto Importer — For nodes.

  • Custom module — For nodes.

Add Attributes in XML

While inside an XML element (after typing < and the element type), clicking Space opens a dialog showing the attributes that are available inside the element.

XML element auto-complete helper.

This is available while in the following editors:
  • Auto importer.
  • Custom modules.

Running tests

When working with K-fields, your code is automatically executed as long as it doesn't contain any warning or errors. You can also trigger a manual execution.

For R-fields, click Run on the bottom margin.

For K-fields, there are two ways to run tests:

  • Provide a specific survey ID next to with survey ID and click Run to run your code against one specific survey record. Use this to check corner cases and verify that they behave as expected. If you don't provide a survey ID, a random one is picked.

    Provide a Survey ID and click "Run".

  • Click Testing Tools and then Run Test to run your code against multiple randomly sampled surveys. This test also verifies that the performance is within the expected range.

    Testing tool showing an error: Unmatched '{'

The upper-right pane shows which code-path has been taken in the latest test execution. In the K-field editor, the path matches the Survey ID on the bottom-left. The line highlight colors indicate:

  • Green is a condition that evaluated positively.
  • Red is a condition that evaluated negatively.
  • Gray lines were not executed.

Testing Tool showing success

Additionally, the upper-right pane shows variable values. Every time a variable or field is referenced, its value is displayed in a table. Use this to debug complex calculations knowing the exact intermediate values the code is generating. Mouse over the variable value blue box to open a dialog with more value details. This is particularly useful when working with R-fields, where you can see exactly what the query is doing. The value inlined in the box may be condensed to remove clutter (that is, very long strings could be abbreviated even if the value is being preserved).

Variable values