The script editor lets you write and execute scripts from the back-office tool, which is also present in the administration and repository views.
It is based on GraalJS syntax.
When used in the back-office, this tool features a grid to display the content returned by script, in addition to the text display of messages and results.
This same tool is more limited in the administration and repository contexts, as it is not possible to display grid content.
In this documentation, we'll assume we're in the CMS back-office environment.
To access the tool, you must have the "Tool Script" right in the "Other tools" category.
This tool is divided into 3 zones:
After successful execution of a script , the script part is retracted to display the grid and the console with the results of the script.
Only the first 100 results are displayed in the grid.
All scripting functions are described in the help section, accessible via the question mark associated with the script tool. Clicking on it opens the script help and the various possibilities. Documentation depends on your environment. It includes tutorials, directly accessible variables, including logging and monitoring utilities, and functions. For each point, you'll find examples of use.
In particular, you will find functions for retrieving the current selection (Ametys.selection), tracking (Ametys.console, Ametys.getLogger(...) or Ametys.progressionTracker), presenting content in a grid(Content.toGridFormat(...)), sending mail (Ametys.mail), creating reports (Report), searching(Repository, Solr, SQL) and content manipulation(Content), as well as other elements for accessing API.
Scripts are considered searches. If you have the plugin Queries Directory, you can save your scripts in the same way as you save a search query.
Enriching the repository
If there are pieces of code that you regularly use in your scripts, you are encouraged to enrich your repository so that they are available in all your scripts. To do this, please refer to the Script repository enrichment documentation.