Groovy
Groovy is a scripting language that is very close to Java. The syntax is almost identical to the syntax of Java, with some enhancements. For example, in Groovy it is possible to make a typeless declaration of variables if you want to. Intrexx uses Groovy mainly for controlling processes, performing complex calculations, as well as complex queries. Due to the similarity to Java, it is possible in most cases to copy scripts from the diverse Java world and reuse them in Groovy. Here, too, you can integrate your own Java classes. The API offers several ways to access important Intrexx functionalities and objects.
Click here for general information about scripting in Intrexx.
Intrexx Standard Library
In the Groovy script editor, you can access the Intrexx Standard Library on the "libraries" tab. If you select an entry in the library, you can access these buttons at the bottom right of this area:
Show description
Shows the description of the currently selected function with an example script.
Open link
Links to the corresponding page that provides more information. The page that opens also shows the classes, interfaces, methods or properties that the currently selected function can be used for. This opens the exact page with the classes, interfaces, methods or properties that you can use for the currently selected function.
Below you will find a description of the functions that are included.
Application structure
Application property from data record object
Reads application properties from a data record object. Replace "myMethod()" in the example script with the desired method.
Example
Returns the GUID of the application that the record belongs to.
Snippet
Data group property from data record object
Reads data group properties from a data record object. Replace "myMethod()" in the example script with the desired method.
Example
Returns the GUID of the data group that the record belongs to.
Snippet
Application info
Information about the application with the stated GUID. Replace "myMethod()" in the example script with the desired method.
Example
Returns the GUID of the application.
Snippet
Control info
Returns information about the control with the stated GUID. Replace "myMethod()" in the example script with the desired method.
Example
Returns the GUID of the page that contains the control.
Snippet
Data group info
Information about the data group with the stated GUID. Replace "myMethod()" in the example script with the desired method.
Example
returns the GUID of the data group:
Snippet
Data field info
Information about the data field with the stated GUID. Replace "myMethod()" in the example script with the desired method.
Example
Returns the GUID of the data field:
Snippet
Reference info
Returns information about the reference with the stated GUID. Replace "myMethod()" in the example script with the desired method.
Example
Returns the GUID of the reference:
Snippet
Application API
JSON response (for Groovy endpoints)
The following snippet can be used in Groovy endpoints. It differs from the existing example by the absence of the json() call and especially in terms of the exception handling. The latter does not work in the Application API because it is taken over by Framework.
Snippet
Parse JSON body from request (Groovy endpoints)
The following code snippet can be used to parse JSON content that was transmitted in the body of an HTTP request.
Snippet
Access to path variables
The following code snippet can be used to access path variables of Groovy endpoints. The values have the data type defined in the configuration of the endpoint.
"g_pathVariables" is also available in Groovy scripts of processes. However, the value can be null if the process was not triggered by a call of the Application API.
Example:
Check if path variables are present
Snippet
Access to query variables
The following code snippet can be used to access query variables of Groovy endpoints. The values have the data type defined in the configuration of the endpoint. "g_queryParameters" is also available in Groovy scripts of processes. However, the value can be null if the process was not triggered by a call of the Application API.
Example:
Check if query variables are present
Snippet
Set HTTP status code for exception
Snippet
Class GroovyHttpServletResponse
Setting HTTP status code by exception
Snippet
Language constants
Every text element used by default in Intrexx is defined in the global language constants. Click here for general information about this subject.
Example for accessing a global language constant:
Returns the value that the global language constant has in the default portal language. Replace "PORTAL_CONST_NAME" in the example script with the name of the desired language constant.
Example
Returns "Next" (label of the "Next" button, which you will find in many dialogs, in German, the default language of the sample portal).
Snippet
Access global language constant in a specific language
Returns the value that the global language constant has for the specified language. Replace "PORTAL_CONST_NAME" in the example script with the name of the desired language constant.
Example
returns the value that the global language constant has in English.
Snippet
Access application language constant
Returns the value that the application language constant has for the default portal language. Replace "APP_CONST_NAME" in the example script with the name of the desired language constant.
Snippet
Access application language constant in a specific language
Returns the value that the application language constant has for the specified language. Replace "APP_CONST_NAME" in the example script with the name of the desired language constant. Replace the language code with the two-letter ISO code, e.g. "en" for English.
Snippet
Imports
Intrexx AccessController
Class that can be used to check whether access requests should be allowed or denied based on the security guidelines currently in effect.
Snippet
IFilter
Snippet
WorkflowException
Exception handling of processes.
Snippet
Objects in Groovy context
PageActionHandler and PageRenderingHandler
g_appGuid
g_handlerGuid
g_page
g_action
g_binding
Access to all bindings that are available at the time of access.
Snippet
g_context
The current processing context.
Snippet
g_ctx
BPEE processing context - only available in the context of a web service.
Snippet
g_dataCollection
The page that serves as a portlet or the DataCollection, which is then loaded.
Example 1
Access a table:
Example 2
Access a data record:
Snippet
g_dbConnections
Access available database connections.
Snippet
Class GroovyContextConnections
g_dbQuery
Object for generating and performing database queries. Instead of "executeAndGetScalarValue", we recommend that you use the typed methods (e.g. executeAndGetScalarValueIntValue, executeAndGetScalarStringValue).
Snippet
g_defaultLanguage
This string contains the language of the portal that is selected as the default language in Portal properties / Regional settings / Languages.
With println(g_defaultLanguage), for example, the corresponding language code can be written to the process log file (e.g. "de" or "en").
Example:
Snippet
g_defaultLocaleId
This string contains the location-dependent format of the portal, which is selected as default in Portal properties / Regional settings / Format.
With println(g_defaultLocaleId), for example, the corresponding language code can be output in the process log file (e.g. "de" or "en").
Snippet
g_dgFile
The Groovy handler can be used in Groovy workflow actions and in Groovy handlers for the Application API. It can be called via "g_dgFile".
Copying files
Examples:
Parameters:
guid: Data field GUID of the file field
id: Record Id, (for composite PFs Intrexx serialization format (id= 1, lang= en) or separately for each PF)
id_%field_name%: Value for primary key field with name
replaceMode: true/false (default: false) If "true", all existing files will be replaced
triggerWorkflow: true/false (default: false) If "true", the workflow is triggered on change
file: Can be type "String", "File", "Path", "FileMap" or a FileInformation object
mode: append(default), appendFirst, replace, delete
file: The source file, type "String", "Path", "File", FileInformation (mode != delete)
For mode: append/appendFirst
name: The name of the file (must be unique, new with the API)
For mode "replace", specify either fileId, replaceName, or pos – see the following:
fileId: The file with the that id should be replaced
replaceName: The file with that name should be replaced
pos: The file at this position is to be replaced (first file has position 0)
If mode "delete", specify either fileId, name, or pos – see following:
fileId: The file with the that id should be replaced
name: The file with that name should be replaced
pos: The file at the corresponding position is to be replaced (first file is position 0)
files: Array of file, Strings (path to file), java.io.File, java.io.Path, FileInformation
Move files (like copying files)
Has additional parameter "deleteAlways" (default: "false")
If deleteAlways=true, the source file will also be deleted if an error occurs while moving.
In the case of "move", FileInformation is not allowed as a source file.
Delete files
Parameters:
guid: Data field GUID of the file field
id: Record Id, (For composite PF's Intrexx serialization format (id= 1, lang= en) or separately for each PF
id_%field_name%: Value for Primary Key field with name.
Without fileId, name or pos, all files will be deleted
fileId: Id of the file to be deleted.
name: Name of the file to be deleted
pos: Position of the file to be deleted (0 = first file)
Get files
Example for copying files with multiple PK
Remark about en.uplanet.lucy.server.businesslogic.util.FileDefinition and the methods "getFileInformation"/"getFilesInformation"
For copying, the FileInformation Object can be used as a source file parameter. This allows files to be copied from another data set.
Example:
g_dirWorkflow
Only available in processes- returns the directory of the current process. This directory should be read-only.
Snippet
g_dirWorkflowTmp
Access the process's temporary working directory on the server. The directory is available to all subsequent process elements until the process is ended.
Snippet
g_event
Only available in processes - contains event that triggered the current workflow. Note that comparisons to the current event (see script example) must always be performed relative to the interfaces and never to the concrete classes.
Snippet
g_exception
Contains the exception that was caught. This must be examined and then it must be decided whether the ErrorHandler is responsible for it. Common criteria for this are:
-
The exception was thrown by an exception of a certain type.
-
The exception was thrown by an exception of a certain type and the error message has a certain content (e.g. starts with "my-custom-prefix:").
See also readme.txt and handler_50_xxx.groovy.example in the portal directory internal/system/vm/html/errorhandler/custom.
Snippet
g_fileScript
The path of the current script as a java.io.File. This object is not available in the context of a web service.
Example
Snippet
g_guidSelf
Contains the GUID of the current process object (action, condition or event handler). This variable is only available in processes.
Snippet
g_guidWf
Contains the GUID of the current process. This variable is only available in processes.
Snippet
g_i18n
Access language constants
Snippet
g_json
The g_json object implements a few simple use cases related to JSON:
-
Parsing JSON text
-
Serializing objects as JSON text
-
Generating JSON objects
-
Sending GET requests and parsing the response as JSON
Example of JSON parsing
Snippet
g_language
This string contains the language of the current user, which is set in his account in the user management under "Organization".
With println(g_language) e.g. the corresponding language code can be written to the process log file (e.g. "de" or "en").
Snippet
g_localeId
This string contains the format of the current user, which is set in his account in the user management under "Organization".
With println(g_localeId) e.g. the corresponding language code can be written to the process log file (e.g. "de" or "en").
Snippet
g_log
Writes the entry in the log file that belongs to the processing context of the script.
Snippet
g_om
Object for accessing the user management.
Snippet
Intrexx provides a wide range of extended options for process-controlled user management. With access objects and methods, new users, among other things, can be created and managed in Groovy actions. The globally available, pre-initialized object "g_om" serves as an entry point for the portal organizational structure in processes. With this object, principle use cases such as searching for a user or generating a new password can be implemented. These methods can be used as "normal" method calls. All available methods can be found in our JavaDocs:
Class GroovyOrgStructureWrapper
Examples
In addition, the object "g_om" has access to more methods that can be called in conjunction with a closure to implement subsequent actions. These methods can be recognized by the groovy.lang.Closure parameter specified in the JavaDocs, e.g. GroovyOrgBuilder.createUser(groovy.lang.Closure p_closure). Within such a closure, methods of any class can be called that are documented in each of the defined links. The following methods can be called with a closure:
A new Intrexx user can be created with this. The following properties can be set within the closure, where the properties name and loginName are required, the others are optional.
Property |
Data type |
---|---|
birthday |
Date |
city |
String |
container |
Object |
country |
String |
defaultLanguage |
String |
defaultLayout |
String |
deletable |
Boolean |
deleted |
Boolean |
description |
String |
disabled |
Boolean |
dn |
String |
emailBiz |
String |
emailHome |
String |
employeeNo |
String |
enterDate |
Date |
externalLogin1 |
String |
externalLogin2 |
String |
externalLogin3 |
String |
externalPassword1 |
String |
externalPassword2 |
String |
externalPassword3 |
String |
externalPrimaryGroupId |
Integer |
female |
Boolean |
firstName |
String |
fullName |
String |
gender |
Integer |
guid |
String |
id |
Integer |
internalUsn |
Integer |
lastName |
String |
loginDomain |
String |
loginDomainLwr |
String |
loginName |
String |
loginNameLwr |
String |
male |
Boolean |
memberOf |
Collection<?> |
middleName |
String |
name |
String |
password |
String |
passwordChangedDate |
Date |
passwordExpires |
Boolean |
passwordHash |
String |
phoneBiz |
String |
phoneFax |
String |
phoneHome |
String |
phoneMobileBiz |
String |
phoneMobileHome |
String |
phonePager |
String |
poBox |
String |
postalCode |
String |
priority |
Integer |
rplGuid |
String |
salt |
String |
showUser |
Boolean |
state |
String |
street |
String |
timeZone |
TimeZone |
title |
String |
userImageContentType |
String |
userImageFile |
File |
userImageMetaInfo |
String |
For the "container" and "memberOf" properties, you can optionally specify the GUIDs, the unique names of the containers, roles, sets or groups and paths in the organizational structure.
Example
Returns all currently logged-in users. "p_bIncludeAnonymous" allows you to define whether anonymous sessions should be included in the result. Additional filters can be applied via the Groovy closure.
Example
Returns all currently logged-in, non-anonymous users without double entries. Additional filters can be applied via the Groovy closure in the same way as "g_om.getLoggedOnUsers(boolean p_bIncludeAnonymous, groovy.lang.Closure p_closure)”.
Allows you to work in the portal organizational structure.
Example
The following methods can be called within the OrgStructure closure:
-
isUser()
-
isSet()
-
isGroup()
-
isDistList()
-
isContainer()
-
isOrganization()
-
isOrgUnit()
Generates a list of the GUIDs of all users that belong to a specific or multiple groups.
Example
"00A303288634E154D755732E478F2BE0D9AD36F7" is the GUID of the group copied from the "Users" module. Multiple group GUIDs or set GUIDs can be entered.
g_parameter
Object for accessing parameters.
Example
def customerid = g_parameter.get("customerid")
Snippet
Page properties - "Parameter" tab
g_permissions
This class is intended to check and query permissions. The usage is shown in the "JSON response" template for the use case there. Check checkPermission(Permission) and check(Closure) as to whether the desired permissions are granted. Otherwise, a java.security.AccessControlException is thrown. hasPermission(Permission) and has(Closure) work analogously, but return a boolean value that indicates whether or not the requested permissions have been granted. The closure methods delegate to the above-mentioned GroovyIxAccessControllerDelegate object and require a map that assigns actions to the object names. Example: Check access permissions to the application <application GUID>, read permissions to the data group <data group GUID> and write permissions to the data group <another data group GUID>.
Example
Snippet
Class GroovyIxAccessController
Class GroovyIxAccessController.GroovyIxAccessControllerDelegate
Classes from de.uplanet.lucy.security.permission
g_portal
Object for accessing portal properties such as name or base URL.
Example
Snippet
g_portlet
Access the respective portlet that should be filtered (in the portlet pool or when rendering the portlet).
Snippet
g_portletPool
Access the portlet pool that should be filtered (collection of portlets), firstly in the portlet pool itself and secondly when rendering the portlet.
Snippet
g_record
Access the current data record.
Example
Snippet
g_rwRecord
Read and write access to the current data record. Can only be used within Groovy PageActionHandlers.
Example
Snippet
g_request
Access the current request, e.g. to read request variables in the process. This variable is only defined if the script was called through a web request.
Snippet
Class GroovyServerBridgeRequest
g_rtCache
RtCache - Access to data groups, applications, fields etc.
Example
Snippet
g_session
The current session.
Example
Snippet
sharedState
sharedState where variables and values can be written and read later.
Example
Snippet
g_sourcePage
Returns, for example, the GUID, application GUID or RecID of the page that sends parameters.
Example
Snippet
g_springApplicationContext
Spring application context.
Snippet
g_store
The following script shows how to use g_store.ephemeral to set a system-wide retrievable ephemeral name-value pair and consume it elsewhere.
Snippet
g_sysDg
With this object, values can be read from a system data group.
Example
Snippet
g_syslog
Logging object for writing to the portal log file (portal.log).
Snippet
g_ws
Object for explicitly calling a web service. Only available in scripts that are defined in a web service.
Snippet
Closures
The predefined closures can be called in the same way as functions.
checkInterrupted()
Checks whether either
-
the thread that performs the process has received an interrupt request from another thread or
-
the timeout defined for the process has been exceeded.
Use this call in scripts that should behave cooperatively in such cases.
Snippet
createTemporaryDirectory()
Generates a temporary working directory that is available until the process has ended.
Snippet
Class CreateTemporaryDirectoryClosure
currentTimestamp()
This closure returns the timestamp of the current transaction. This value is not changed until the transaction has finished being processed.
Example
Snippet
getStackTraceString()
Returns the entire StackTrace of an occurred error as a string. The closure "getStackTraceString()" requires a parameter with the type java.lang.Throwable, i.e. an exception.
Snippet
Class CreateStackTraceStringClosure
newGuid()
Generates a new GUID.
Snippet
now()
Generates a new date (now) as a timestamp or ValueHolder.
Snippet
parseGuids(strText)
Parses GUIDs from the transferred string (e.g. as a pipe-separated list) and returns a TreeSet with the found GUIDs.
Snippet
vh()
Generates a new ValueHolder from the transferred object.
Snippet
Class CreateValueHolderClosure
Databases
Data groups
Find data group via GUID
How to identify the name of a data group:
def strName = g_rtCache.dataGroups["C399FB1F398D76E91BC7DC679E1E4DDB9F5CEB9C"].name
Snippet
Reference data group in SQL via GUID
So that you don't have to use a static data group name in SQL statements, thus avoiding problems when importing or making changes to the data group, A data group can be referenced using its GUID instead of its name with the aid of this client function. This is only available via the Intrexx database API.
Example
Instead of "executeAndGetScalarValue", we recommend that you use the typed methods (e.g. executeAndGetScalarValueIntValue, executeAndGetScalarStringValue).
Snippet
Get all column names of a data group
Returns a list of column names from the data group with the stated GUID.
Snippet
Intrexx database API
Prepared statement with SELECT
Executes a SELECT statement as a prepared query. Afterwards it is iterated over the results in the result set.
Example
Snippet
Prepared statement with INSERT
Executes an INSERT statement as a prepared query.
Example
Snippet
Prepared statement with INSERT (with closure)
Executes an INSERT statement with a closure as a prepared query.
Example
Please note: If the statement is to be reused, e.g. within a loop, the prepared statement version without a closure is more efficient.
Snippet
Prepared statement with UPDATE
Executes an UPDATE statement as a prepared query.
Example
Snippet
Prepared statement with UPDATE (with closure)
Executes an UPDATE statement with a closure as a prepared query.
Example
Please note: If the statement is to be reused, e.g. within a loop, the prepared statement version without a closure is more efficient.
Snippet
Prepared statement with DELETE
Executes a DELETE statement as a prepared query.
Example
Snippet
Prepared statement with DELETE (with closure)
Executes an DELETE statement with a closure as a prepared query.
Example
Please note: If the statement is to be reused, e.g. within a loop, the prepared statement version without a closure is more efficient.
Snippet
Read a single value from a database query
Reads a single value from a database query. If the result set is empty, or the value is null, the fallbackValue is returned. If the return data type should be defined more precisely, typed method calls such as executeAndGetScalarBooleanValue(...) can be used.
Example
or with a prepared statement
Instead of "executeAndGetScalarValue", we recommend that you use the typed methods (e.g. executeAndGetScalarValueIntValue, executeAndGetScalarStringValue).
Snippet
Read a single value using a prepared database query
Reads a single value from a database query. If the result set is empty, or the value is null, the fallbackValue is returned. If the return data type should be defined more precisely, typed method calls such as executeAndGetScalarBooleanValue(...) can be used.
Example
Instead of "executeAndGetScalarValue", we recommend that you use the typed methods (e.g. executeAndGetScalarValueIntValue, executeAndGetScalarStringValue).
Snippet
JDBC
Prepared statement with SELECT
Executes a SELECT statement as a prepared query. Afterwards it is iterated over the results in the result set.
Snippet
Prepared statement with INSERT
Executes an INSERT statement as a prepared query.
Snippet
Prepared statement with UPDATE
Executes an UPDATE statement as a prepared query.
Snippet
Prepared statement with DELETE
Executes a DELETE statement as a prepared query.
Snippet
System data source
System database connection.
Example
Snippet
Class GroovyContextConnections
External data source
Connection to an external data source. The name to use is the given name of the external connection defined in the Integration module.
Example
Snippet
Class GroovyContextConnections
Determine the database type
Identifies the type of database.
Snippet
Class GroovyContextConnections
Web services
Execute web service call
Calls the underlying web service. Only valid for scripts defined within a web service.
Snippet
Read web service input values
Read values defined as input parameters for a web service. Use the name of the control, which contains the value, as the variable name.
Example
Snippet
Read web service response values
Read values defined as response parameters from a web service. Use the name of the control, where the response value will be written, as the variable name.
Example
Snippet
Case differentiation
switch statement for Groovy condition
Usable in processes. The returned values correspond to the outgoing connections (connection ID) of the Groovy condition.
Snippet
switch statement for data group events
Usable in processes.
Snippet
Records from global data group timers
Distinguish the first record from the subsequent records that are delivered by a global data group timer.
Snippet
Mathematical calculations
Business rounding
Round half away from zero with the option of defining the number of decimal places.
Example
Snippet
Mathematical rounding
Round to even with the option of defining the number of decimal places.
Example
Snippet
Date / Time
Formatting date values
Here you can find script for formatting date values.
Snippet
Duration in days
A data record contains data for a start and an end date. The duration between these two date values is calculated. Please note that time zones are not considered.
Snippet
Parse ISO date string
Parses an ISO formatted string into an "java.util.Date" object.
Example
Snippet
Parse date to ISO string
Formats a date object as an ISO string.
Example
Snippet
Now as timestamp
Snippet
Timestamp for system values
This closure returns the timestamp of the current transaction. This value is not changed until the transaction has finished being processed.
Snippet
Groovy email (simple)
Create a simple text email.
Snippet
Groovy email
Create an HTML email with inline images and attachment.
Snippet
Send email via Ant
Please note: Sending the email is not part of the transaction, but is executed immediately and regardless of the success of the transaction.
Snippet
Files and directories
Identify disk space
Identifies the free and total disk space.
Snippet
The directory of the current workflow
Returns the directory of the current process. This directory should be read-only.
Snippet
Temporary workflow directory
Access a temporary workflow directory. The directory is also available to subsequent workflow objects. It is deleted as soon as the workflow has been fully executed.
Snippet
Work in a temporary directory
Uses a temporary directory for processing.
Snippet
Add file to data record
Add a file to an existing record. With "copyFileToIntrexx(...)" the source file is copied and remains at its storage location. An analog call can be made with "moveFileToIntrexx(...)". In this case, the source file will be moved to Intrexx.
Parameters:
p_ctx - Current processing context (g_context)
p_fileSrc - File to be added to record
p_strFieldGUID - Data field GUID
p_recId - ID of record that the file should be added to
p_bTriggerWorkflow - Should a workflow be triggered that responds to data record changes?
The "p_bTriggerWorkflow" parameter of the "FileUCHelper" class is not implemented so it always has the value "false".
Example
Snippet
Remove file from data record
Deletes a file from a record.
Parameters:
p_ctx - Current processing context (g_context)
p_strFieldGUID - Data field GUID
p_recId - ID of record where the file should be deleted
Example
Snippet
Read text file
Reads the content of a text file with the stated encoding. Do not use for large volumes of data.
Snippet
Read text file line by line
Reads the content of a text file line by line with the stated encoding.
Snippet
Write to text file
Writes a text output to a file with the stated encoding.
Example
Snippet
Session / User
Name of the current user
Snippet
Email address of current user
Snippet
Anonymous session or not?
Snippet
Access the organizational structure
Snippet
Users online
Get a list of all non-anonymous, logged-in users.
Snippet
Set new password for user
Sets a new password for the stated user.
Snippet
User Manager
Create user (basic)
Snippet
Create user
Snippet
Edit existing users
Snippet
Classify GUIDs
Classify GUIDs by
-
User
-
Container (organization, organizational unit, ...)
-
Set (group, rol, DistList, ...)
-
unclassified GUID
Snippet
Categories
Date / Time
Snippet
IValueHolder
Snippet
Class GroovyIntrexxValueHolderCategory
Info
System information
Snippet
Intrexx version
Returns the Intrexx installation version.
Snippet
Error handling and debugging
Stacktrace as string
Snippet
Groovy context
Snippet
def dumpBinding = { def sbuf = new StringBuilder() sbuf << "Dump the Groovy binding:\n" binding.variables.each { k, v -> if (v && v.metaClass && v.metaClass.respondsTo(v, "dump")) sbuf << "${k} = ${v.dump()}\n" else sbuf << "${k} = ${v?.toString()}\n" } sbuf.toString() } g_log.info(dumpBinding())
Define an error handler for a script
Usable in
-
Groovy page
-
Action and rendering handlers
Snippet
Groovy server scripts
JSON response
Please note that a permissions check (IxAccessController) is required before any action that is triggered by a user.
Snippet
Possible variations of the script above
Closure without or with exactly one parameter
If the closure declares a parameter, the exception that occurred is transferred to the closure in the first parameter (e).
Snippet
Closure with two parameters
In the first parameter (e), the exception that has occurred and in the second parameter (err) an ErrorResponseData object is passed to the closure. The ErrorResponseData object can be configured in the closure according to the respective requirements.
Snippet
With a string
The stated string is sent to the client in the response body.
Snippet
Assign another object
In a JSON response scenario, an attempt is made to generate JSON from the object. If the response is not JSON, an attempt is made to output the object in a suitable manner as text.
Snippet
Velocity
Create text from a Velocity template
Snippet
Create file from a Velocity template
For security reasons, Velocity files can only be executed if they are stored in one of the following subfolders:
-
internal/system/vm
-
internal/layout/vm
-
internal/application/vm/
-
internal/application/resource
-
internal/workflow/<GUID>/velocity/
Request-Variable
g_request.get(...)
Snippet
Class GroovyServerBridgeRequest
rq_Lang
Returns the language the logged-in user is currently using.
Snippet
REMOTE_ADDR
IP address of the client computer.
Snippet
SERVER_PORT
Snippet
HTTP_HOST
Snippet
HTTP_REFERER
Snippet
HTTP_COOKIE
Snippet
HTTP_USER_AGENT
Snippet
SCHEME
HTTP or HTTPS
Snippet
Images
Scale image
Supported formats are PNG, JPEG (JPG), and BMP.
Snippet
Determine the size of an image
A file object or a path as a character string can be transferred as parameters.
Snippet
Iterate over image metadata
Here is an example of metadata extraction.
Snippet
Logging
Write info to the portal log
Writes an INFO log entry to the portal log file (portal.log). This method can be used if the log file of the current processing context is not portal.log, but portal.log should be used.
Snippet
Write info to log file
Writes an INFO entry to the log file that belongs to the execution context of the script.
Snippet
Write warning to log file
Writes an WARN log entry to the portal log file (portal.log). This method can be used if the log file of the current processing context is not the portal.log, but portal.log should be used.
Snippet
Write warning to log file
Writes a WARN entry to the log file that belongs to the execution context of the script.
Snippet
Write error to log file
Writes an ERROR log entry to the portal log file (portal.log). This method can be used if the log file of the current processing context is not the portal.log, but portal.log should be used.
Snippet
Write error to log file
Writes an ERROR entry to the log file that belongs to the execution context of the script.
Snippet
Read the statistics logs
Snippet
Connector for Microsoft Exchange
Current Exchange connection
Returns the current connection to Microsoft Exchange.
Snippet
Mailbox name of the current Exchange user
Returns the mailbox name of the current Exchange user.
Snippet
Save email locally as an EML file
Saves an email locally as an EML file. Alternatively, saveMessageAsMSG can be used to save an email as a MSG file.
Parameters:
-
strMessageId - ID of message to be saved
-
fileMail - File object to save the message
Snippet
Interface IExchangeMessageUtil
Save email attachments
Save attachments of an email defined by strMessageId.
Snippet
Set the out of office message
Writes the out of office message and sets its status to active. Attention: The text is set for internal and external out of office messages.
Snippet
Interface IExchangeMailboxUtil
Get folder information
Gets information about a folder from the Exchange account.
Snippet
Create folder
Create an Exchange folder (in this example in the default inbox folder)
Parameters:
-
Name of the parent folder
-
Name of the new folder
-
Exchange content class
Snippet
Interface IExchangeMailboxUtil
Add attachment to an element
Adds an attachment to an existing item (e.g. an appointment).
Parameters:
-
strItemId - ID of item that the file should be attached to
-
fileAttach - File to be attached
-
strFileName - Name of the attachment
-
strMimeType - The attachment's mime type. If null, application/octet-stream will be used
-
bIsContactPhoto - True, if an image file should be used as contact photo
-
bDeleteAfter - True, if the file should be deleted after being attached
Snippet
Create an Exchange appointment
Creates an appointment for the current user.
Parameters:
-
dtStartDate - Start date of the appointment
-
dtEndDate - End date of the appointment
-
strSubject - Title of the appointment
-
strBody - Description of the appointment
If additional properties are set or updated with set()-methods after creating the appointment, they have to be saved with appointment.save() afterwards.
Example
Snippet
Interface IExchangeAppointmentUtil
Create an Exchange contact
Creates a new contact for the current user.
Parameters:
-
strLastName - Last name of the contact
-
strFirstName - First name of the contact
-
strMail - Email address of the contact
-
strMailbox - The user's mailbox that the contact should be added to. If null, the current user's mailbox is used.
If additional properties are set or updated with set()-methods after creating the contact, they have to be saved with contact.save() afterwards.
Example
Snippet
Interface IExchangeContactUtil
Create and end Exchange email
Creates a new email for the current Exchange user.
Parameters:
-
strFrom - Sender address
-
strTo - Recipient address
-
strSubject - Subject
-
strBody - Message text
If additional properties are set or updated with set()-methods after creating the message, they have to be saved with message.save() afterwards.
Example
Snippet
Interface IExchangeMessageUtil
Create an Exchange note
Creates a note for the current user.
Parameters:
-
strText - Text of the note
-
strMailBox - The user's mailbox that the contact should be added to. If null, the current user's mailbox is used.
Example
Snippet
Create an Exchange task
Creates a task for the current user.
Parameters:
-
dtStart - The task start date
-
dtDue - The task due date
-
strSubject - The task subject
-
strMailBox - The user's mailbox that the note should be added to. If null, the current user's mailbox is used.
Example
Snippet
Portlets
Only show portlet if table contains data records
The following script means that the portlet is only displayed if the table contains data records; the "Restrict display of the portlet on the web by Groovy script" setting must be activated. The script can also be used if the "Restrict selection of the portlet on the web by Groovy script" is activated. In this case, the portlet will no longer be listed under "Portlets and applications" on the portlet settings page and cannot be added to the portal page if the table does not contain any records.
Snippet
Tips & Tricks - Filter portlets with Groovy
Restrict portlets in the portlet container
To restrict portlets in the portlet container, a list with portlet objects must be returned. You can retrieve all available portlet objects with "g_portletPool". In this example, only the portlet with the GUID entered instead of the placeholder would be available.
Snippet
Control the display with a Boolean value
By returning a Boolean value, you can control whether a portlet should be displayed or not, for example in the portlet properties:
Snippet
WebSockets
Sending a text message
Example
Snippet
Sending a JSON message
Example
Snippet
Check for an interrupt request
Checks whether either
-
the thread that performs the process has received an interrupt request from another thread or
-
the timeout defined for the process has been exceeded.
Use this call in scripts that should behave cooperatively in such cases.
Snippet
Automatic logout of implicitly generated sessions
If a Groovy endpoint is called and the client does not send a valid session ID, then an anonymous session is implicitly generated on the server. The following script allows you to prevent these sessions from staying on the server until the timeout of the anonymous session. The criterion for the automatic logout is that the client has not sent a co_SId session cookie.
Snippet
Start a scheduler job
Input parameters: ID or GUID of the job. The parameters "testParam" and "greeting" from the following snippet are available in the SharedState in the started timer process.
Snippet
Tips & Tricks - Start processes
Run an external program
Runs an external program. Click here for more information.
Snippet
Create a new GUID
Generates a new GUID.
Snippet
Check GUID
Checks whether a specified string is a GUID in Intrexx terms. If the transferred value is null, the method returns false.
Example:
Snippet
Create a ValueHolder
Creates a ValueHolder for a simple data type. If null is transferred, a NullValueHolder will be created. Its value is null, and hasValue() is false.
Snippet
Parse GUIDs
Parse GUIDs from textual input. Multiple parameters are possible.
Snippet
Determining the time zone of the portal
Here you find script for determining the default time zone, which is set in the portal properties in the regional settings.
Snippet
Determine start time and uptime of the portal
Snippet
Short links
Template - Groovy API for short links
Criteria for matching short links with the configured short link rule:
Match criteria
1.) equal static path prefix
2.) equal number of path components or path components + variables and equal number of slashes
3.) Path components which are not variable must be equal
For variable path components, the variables are assigned the values of the path components.
Creating target URLs
Target URLs can be absolute or relative to the root directory of the website. In the first instance, any number of targets can be given. In the second instance, the website is assumed to be the target, which is requested in the website browser.
The variables allocated during matching can be used in the target URL and as a part of the path and even the query string. Query string parameters which are in the input URL but not the configured target URL are saved to the output URL.
Examples
Snippet