Creating and running scripts
Last updated
Last updated
Scripts can be accessed from the navigation panel.
Clicking on + New Script will create and open a new empty Violet Script. Users should give their script a unique and descriptive name in the settings panel.
A script will open with a blank text box where users can start typing their python code, which will automatically save.
To start, type in print('hello world')
and hit Run Script. This will execute the script and display the output in a new output window underneath the script.
To use Violet Variables, you must have other data in the system that you would like to use in a script, either through creating integrations or by creating parameters. In my example, I have created a Duro Integration that is pulling in a variety of components.
To create a Violet Variable use the reserved Violet["variable_name"] syntax within your script, where the variable_name can be replaced with the name of your choice. Variable names must be unique within each script and can only contain letters and numbers. You can use an underscore to separate words.
After creating a variable, you'll be prompted to link the variable to the data of your choice. Each variable you have created will show up in this sidebar, with a link symbol next to it. Clicking on the link will open a popup that lets you search through the data in the system. Select the property you would like to link to that Violet Variable.
The selected property value will display next to the link symbol. Ensure it is correct, and link any additional variables you may have. Hit save to save the links and close the sidebar.
Hit Run Script. Your output will accurately reflect the values of each Violet Variable at the time of the run.
The Live toggle is a setting that will automatically re-run the Violet Script anytime the value of its linked Violet Variables change, as well as generate an output entity displaying the results of the script. If the output of the script is a numeric value, string, or boolean, it will be saved into a property of the entity as well. By default, this will create one output entity per Violet Script which will be updated every run with the new results if the output changes.
The Live toggle can be accessed from the top panel of the Violet Script. The output can be accessed from the Violet Script Outputs section
Example Violet Script Output:
If a Violet Script is Live, users can also choose to save the history of script outputs. This will generate a new output entity each run while preserving the older ones. A timeline of historical runs and their outputs can be viewed from inside of a Violet Script. An out-of-date entity will be tagged with This entity is not the latest revision, and cannot be used as a linked entity in parameters or as a Violet Variable. Turning off history will delete all existing history.
Subscribing to notifications on a Violet Script can let a user know when a Live script has been automatically run due to a changing Violet Variable, and the output has changed. Notifications will be shown in the notifications panel, as well as through Slack if a Slack notification is set up. Subscriptions are individual to each user.
Click on the eye in the top right corner of a script to subscribe to notifications.
Check out these examples of how to run scripts: