VBScripts in Vertec

Visual Basic Scripts

Product line

Standard

|

Expert

Operating mode

CLOUD ABO

|

ON-PREMISES

Modules

Services & CRM

Budget & Phases

Purchases

Resource Planning

Business Intelligence

Created: 20.06.2003
Machine translated
Updated: 13.07.2023 | Note that only Python scripts are to be created.

Note: New scripts should always be written as Python Scripts , not 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 run custom scripts.

The entire Vertec object model can be accessed from a Vertec script. This is done in the same way as accessing it 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.

Objects

The “vertec” object (ivtcsession)

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 up-to-date object in Vertec.
createobject(class type) creates a new object in Vertec of the specified class type.

The list object (ivtcobjectlist)

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:

Characteristicdescription
countreturns the total quantity of objects in the list.
objects(i)returns the i-th object. Note: the list starts at 0 and goes to count-1.

The single object (ivtcobject)

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 based on 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 features of VBScript are available to you.

Example

To get you started quickly, here is a script example. 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 projektliste
dim projekt
dim phasenliste
dim phase
dim i

'---hole alle aktiven Projekte
set projektliste = vertec.eval("projekt->select(aktiv)")

'---Fahre nun durch alle aktiven Projekte durch
for i = 0 to projektliste.count - 1
  set projekt = projektliste.objects(i)
  '---Hole die Phase mit Code des aktuellen Jahres, ausgehend vom aktiven Projekt.
  set phasenliste = projekt.eval("phasen->select (code='" & year(date) & "')")
  '---Wenn noch keine Phase mit dem gewünschten Code vorhanden, neue erzeugen.
  if phasenliste.count = 0 then
    set phase = vertec.createobject("Projektphase")
    '---Setze das Projekt.
    phase.member("projekt") = projekt
    phase.member("code") = year(date)
  end if
next

It is recommended to use Option Explicit 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 feature must be enclosed in double quotation marks. However, the OCL convention applies within the given OCL expression. This requires single quotation marks for string values.