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.
- 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.
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:
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.
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.
-
K-field — For functions and fields.
-
R-field — For functions and fields.
Tip: To see the available cube functions, typecube.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.
- 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.
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.
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.
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).
