Overview
The Code Editor is available anywhere in Etlworks, where the user can enter SQL, JavaScript, Python, or XSLT code.
Code Editor Basics
To access the Code Editor, click Open in Editor
on top of the text field.
By default, the Code Editor opens in a pop-up window.
It then can be extended to the full screen by clicking Enter full screen
and collapsing back to the pop-up window by clicking Exit full screen
.
Code Editor commands
Below are some Code Editor commands and their shortcuts:
# | Shortcut | Command |
---|---|---|
1 | Ctrl+F |
Search |
2 | Ctrl+Shift+F |
Search & Replace |
3 | Click Line:Column |
Go to Line |
4 | Click language selector |
Select color highlighter |
5 | Click Enter or Exit Full Screen |
Enter or exit full-screen mode |
Code Library and Macros
The Code Library contains shared and reusable fragments of code in all supported languages: SQL, JavaScript, Python, shell, and others.
Any user with permission to create and edit Flows can access and update the Code Library.
Macro
Macro is a reusable fragment of code that can be referenced in the Code Editor as {{MacroId:LABEL}}
.
Access the Code Library
The Code Library can only be accessed from the Code Editor. You can hide the Code Library by turning off Macros Library
at the bottom of the code editor popup.
Use the Code Library
Add new code fragment (Macro)
Click Add Macro
to create a new Macro.
Enter the code
, Title
, Label
, and other (optional) parameters and save the Macro. Once the Macro is saved, the Label
cannot be edited anymore.
Edit existing code fragment (Macro)
Click 🖊️
to edit the code and other editable parameters.
Delete existing code fragment (Macro)
Click 🖊️
to open the Macro editor and click Delete
to delete the Macro.
Search code fragments
You can filter existing Macros by name, tag, description, and label.
Copy Macro to editor
Highlight Macro and click Copy macro to editor
.
Copy Macro body to editor
Highlight Macro and click Copy macro body to editor
.
Passing parameters to macros
There are two distinct approaches to passing parameters to macros.
Using parent scope variables
Initialize variable before macro in your script and then use it directly in the macro itself. For example if you create a macro that shortens data variable to 7 characters and adds tree dots at the end:
data = data.substring(0,7) + '...';
you can use it in your script this way:
var data = 'Some long text';
{{SomeMacroId:Shorten data}}
then in the end after macro applied your script will look like
var data = 'Some long text';
data = data.substring(0,7) + '...';
Using macros to import functions
Much better approach is to create function inside of your macro, import it at the beginning of the script and then use it as many times as you want. This will allow you to reuse it in any context without relying on the variables names. Macro from the previous example would become something like this:
function shortenString(string, length) {
if (string.length > length) {
return string.substring(0, length - 3) + '...';
} else {
return string;
}
}
now you can import it to any of your scripts regardless of variable names
{{SomeMacroId:Shorten string function}}
var data = shortenString('Some long text', 10);
var anotherData = shortenString('Even longer text', 20);
Comments
0 comments
Please sign in to leave a comment.