Basics Visual Basic Scripts
Product line
Standard
|Expert
Operating mode
CLOUD ABO
|ON-PREMISES
Modules
Services & CRM
Budget & Phases
Purchases
Resource Planning
Business Intelligence
Note: New scripts should always be Python scripts , are not written as VBScripts. VBScripts are only available for backward compatibility reasons and are not recommended or completely disabled in the cloud clients for security reasons. See also Point 7 of our 10-point plan for a future-proof Vertec installation .
Vertec supports the Microsoft Scripting Engine (Vbscript) to execute custom scripts.
In turn, the entire Vertec object model is accessible from a Vertec script. This is done in the same way as accessing from Word via an (internal) COM / Activex extension.
A script can be created either as a Script entry or in a text editor (e.g. Notepad). More information about Vbscript can be found at: Programming with Vbscript or at: Vbscript Language Reference on the Microsoft homepage.
Scripts that are used repeatedly can be registered in Vertec. They can then be retrieved from the Actions menu item or from the context menu (with the right mouse button). See the article on registering scripts.
Access to the Vertec object system from a script always takes place via the global variable vertec
. This variable is of the IVtcSession object type and has the following main methods (only the most important ones are listed, the full list can be found in the COM Interfaces article):
Characteristic | description |
---|---|
eval(expression as string) | Evaluates the specified OCL expression and returns a list of objects. |
argobject | returns the current object in Vertec. |
createobject(class type) | creates a new object in Vertec of the specified class type. |
In most scripts you will edit a list of objects (e.g. all active projects). The List object is of the Ivtcobjectlist object type and has the following important methods and properties:
Characteristic | description |
---|---|
count | returns the total quantity of objects in the list. |
objects(i) | returns the i-th object. Attention: the list starts at 0 and goes to count-1. |
Individual objects are stored in the IVtcObject object type. A single object can be found either via vertec.argobject, by selecting one from a list of objects (via objects(i)) or as a result of eval(“OCL Expression”). The single object has the following important methods and properties:
Characteristic | description |
---|---|
eval(expression as string) | Evaluates the specified OCL expression , starting from the individual object. |
member(name as string) | Returns the contents of the member with the specified name. For example, <myprojekt>.member(“code”)</myprojekt> returns the project code. Members can also be written:member(“membernamen”) = “your text”. |
classname | returns the class name of the object, e.g. project or project user. |
Otherwise, all functions of VBScript are available to you.
To get you started quickly, here is an example script. This creates a new project phase with the code of the current year for all active projects that do not have such a phase yet:
option explicit dim project list dim project dim phase list dim phase dim i '---get all active projects set projectlist = vertec.eval(“project->select(active)”) '---Now go through all active projects for i = 0 to projectlist.count – 1 set project = Projektliste.objects(i) '---Get the phase with code of the current year, starting from the active project. set phasenliste =projekt.eval(“phasen->select (code='” & year(date) & “')”) '---If no phase with the desired code exists, create a new one. if phaselist.count = 0 then set phase = vertec.createobject(“project phase”) '---Set the project. phase.member(“project”) = project phase.member(“code”) = year(date) end if next
It is recommended to use the Explicit option
, as this prevents variables from being used in the script that were not previously defined.
Also note the use of different types of quotation marks. Double quotation marks denote string values in Vbscript. Therefore, the argument to the eval
function must be enclosed in double quotation marks. However, within the given OCL expression, the OCL convention applies. This requires single quotation marks for string values.