script editor (tool)


 

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.

  1. Scripts tool
    1. Presentation
    2. Features
    3. Backup

Scripts tool

Presentation

To access the tool, you must have the "Tool Script" right in the "Other tools" category.

  1. The tool is then available in the Administration tab.
  2. A contextual Search tab appears
  3. Run and help buttons are available

This tool is divided into 3 zones:

  • At the top, the script area, where script can be written inside a "main" function. Below the script area, there's an "Execute" button to run the script function.
  • At bottom left, taking up the entire width by default, is a grid displaying the contents returned by the execution of script.
  • In the bottom right-hand corner, reduced by default, you'll find the"Console", i.e. the result of the script execution in text format.

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.

Features

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.

Backup

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.

Back to top