You can access Internal Scripts using the Script Selector dialog. To access this dialog, use the menu Document>Scripts.
If you do not have the Script Manager or Script Executor user privileges, this menu option will be disabled.
Click on the image below to learn more about the various sections of this dialog.
A list of scripts in the Site database that you have access to.
Applies the entered text as a dynamic filter to the list of scripts, allowing you to find a specific script easily when there is a large number of scripts in your Site database.
Compile gathers all of the Script code and Module code and checks the code for syntax errors or missing assemblies/modules that are referenced.
Executes the script (if the Compile is successful).
Displays information on the status of the script. If a script has been compiled or executed, you can open the Status dialog to see more information on what happened during those operations.
Select one or more Include options to filter which scripts are displayed in the Script Selector.
Creates a new Script. Select a scripting language and click OK to open the Script Properties dialog.
Opens the Script Properties dialog for the selected script.
Reloads the dialog contents. You may need to click Refresh while a script is executing to get the latest script status.
The Script Properties dialog is used to create and modify internal scripts. Click on the image below to learn more about the various sections of this dialog.
Enter a label for the script.
Enter a description for the script. This field is optional.
Script declarations are code that is expected up front when the script is compiled for the language used. Writing code in C# or Visual Basic involves declaring up front expected code such as Visual Basic Imports or C# using statements.
For example:
Visual Basic |
C# |
Imports System Imports CM4D.Scripting Imports CM4D Imports Microsoft.VisualBasic |
using System; using CM4D.Scripting; using CM4D; |
Declarations in a Script Module must be copied to the Script level Declarations.
Script Access determines which users have access to the script. There are three levels that can be used to determine access:
· Public - available to all users
· Group - available to all users that belong to the selected group
· User - only available to the user that created the script
It is recommended that you set the Script Access to 'User' while you are developing a script. This will prevent anyone else attempting to run an unfinished script. Once a script is fully developed, you can give other users access by changing the Script Access scope to either Group or Public.
Timeout is the interval (in minutes) after which the script will be stopped. The Timeout property prevents potentially infinite loops, and is really the only ‘safety’ mechanism provided for internal scripts.
Compile gathers all of the Script code and Module code and checks the code for syntax errors or missing assemblies/modules that are referenced.
Executes the script (if the Compile is successful).
The Entry Code is the entry point for the script execution. This requires some very specific code that defines the entry point, and any user-defined code is inserted after this. The required code, or shell, is inserted automatically (conforming with the programming language selected) when a new script is created:
|
Visual Basic |
C# |
Start Code |
Public Class CM4DScript Public Sub Execute(cm4dDoc as Cm4DScriptingDoc) |
public class CM4DScript { public void Execute(Cm4DScriptingDoc cm4dDoc) { |
End Code |
cm4dDoc.EndScript() End Sub End Class |
cm4dDoc.EndScript(); } } |
Script Modules are optional, as all script code can be defined in the Declarations and Entry Code. However, Modules provide a way to build reusable code that can be referenced by and included in multiple scripts.
To include a script Module, click Add. In the Script Module Selector, either create a new Module or highlight an existing Module from the list, and then click Select.