Create a shared script using Visual Studio Code
Shared scripts let you maintain and reuse commonly used code in a separate script that can be referenced by one or more other scripts of any type.
-
initialize your working folder
The scripting command only runs on the script code and does not affect the entity property or relation. When you push a script to a new environment, a script entity is created. The action entity that references this script entity is not pushed to the new environment.
To create a shared script:
Every time you save your script, the script watcher compiles and publishes it.
-
In your working folder, create a file with the extension
.csxat the root of the working folder. -
Open the file and add the following header:
RequestResponse#load "./references/Shared.csx" /**------------ Include above to support intellisense on Content Hub types in editor ----------------**/ // Script StartImportantThe script header is determined by the script type. All lines in the header are required.
-
Save the file.
-
In a terminal, run the following command to start the script watcher:
RequestResponsech-cli scripting watch -f <YOUR_FOLDER_PATH>The shared script is created on the Content Hub instance you are connected to.
-
Write the remainder of your script.
-
Run the following command to enable your shared script:
RequestResponsech-cli scripting enable -n <YOUR_SCRIPT_NAME> -
To reference your shared script from other scripts, you can refer to the script by name as shown in the following example:
RequestResponse#load "./references/Action.csx" /**------------ Include above to support intellisense on Content Hub types in editor --------------**/ // Script Start #load "<MY_SHARED_SCRIPT.CSX>" ...