Click here for general information about scripting in Intrexx.
2. Intrexx Standard Library
In the Velocity 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.
2.1. Application structure
2.1.1. Application info
Information about the application with the stated GUID.
Determine group memberships of the current user and
execute further actions based on this.
Snippet
#set($groupGuids = ['EF16F15EDA8562E19D7CD56BF2E43001F119193C', '47DD42CF4203EFDC7B1596E0158BB5B1E810D583'])
#set($userMembership = $Portal.getOrgStructure().getMembershipSets($User))
##Returns true, if $User is member of at least one group, which is defined by its guid in $groupGuids
#if ($userMembership.intersects($groupGuids))
##Not implemented yet
#end
In the following, the Velocity context object "$CalcUtil" for calculating
values will be presented and explained using code examples.
With the
function calculate(),
complex calculation and comparison operations can be performed.
The '( )' brackets can be used to structure the operation.
The values for the calculation and comparison operations being performed
can be read from data fields, sessions, requests, table cells or SharedStates.
2.3.6.2. Operators
The following operators are available in a calculation formula:
+ (Addition)
- (Subtraction)
* (Multiplication)
/ (Division)
< (Comparison: Smaller than)
> (Comparison: Greater than)
<= (Comparison: Smaller than or equal to)
>= (Comparison: Greater than or equal to)
== (Comparison: Equal)
!= (Comparison: Unequal)
&& (Logical connection: And)
|| (Logical connection: Or)
! (Logial operator: Not)
2.3.6.3. Other type categories and methods
In addition to the operators described above, there are additional options to call certain variables or methods in formulae:
Method
Description
Example
datafield
Value from a data field
datafield("C68F6...D3DE7")
datafieldAsNumber
Value from a data field as a number
datafieldAsNumber("C68F6...D3DE7")
session
Value from an existing session of the currently logged-in user
session("sessionValue")
sessionAsNumber
Value from an existing session of the currently logged-in user as a number
sessionAsNumber("sessionValue")
sharedState
Value from the current processing context
sharedState("sharedStateValue")
sharedStateAsNumber
Value from the current processing context as a number
sharedStateAsNumber("sharedStateValue")
requestAsNumber
Value from the current request as a number
requestAsNumber("rq_requestValue")
abs
Absolute value
abs(-1)
For the types with the suffix "AsNumber", Intrexx will attempt to cast the
incoming values, provided it is technically possible.
Without this cast, an exception will occur when you use string data fields, for
example. The Boolean values "true" and "false" will be cast accordingly
to 1 and 0, respectively. It is also possible to state a fallback as a
second method parameter. This fallback is used if the first parameter
is null or empty. This fallback value can also be a formula.
Snippet
//returns -1, if access to the SharedState variable
"sharedStateValue" returns null or the value is not defined.
sharedState("sharedStateValue", -1)
//returns 5, if access to the request variable "rq_custom" returns null
or the value is not defined.
requestAsNumber("rq_custom", (10/2))
//returns 0, if the data field contains null or has not been defined.
datafield("C68F6...D3DE7", 0)
2.3.6.4. Error handling
To catch potential errors (e.g. dividing by 0), the following methods
can be used in a formula:
Method
Description
Example
zeroOnError
Returns 0 in the case of error
zeroOnError(10/0) == 0
oneOnError
Returns 1 in the case of error
oneOnError(10/0) == 1
fallbackOnError
Returns the fallback value in the case of error
fallbackOnError(10/0, 2) == 2
2.3.6.5. Rounding functions
Number values can be rounded in formulae. The parameter "scale" describes
the number of decimal places.
Method
Description
roundLong
Round half away from zero
roundLongHalfAwayFromZero
Corresponds to roundLong
roundLongHalfEven
roundLongHalfUp
roundLongHalfDown
round(scale)
Round half away from zero to the number (scale) of decimal places
(roundLong corresponds to round(0))
roundLongHalfAwayFromZero(scale)
Corresponds to round(scale)
roundLongHalfEven(scale)
roundLongHalfUp(scale)
roundLongHalfDown(scale)
2.3.6.6. Case differentiation
Conditions in formulae can be checked in advance with case differentiation,
and based on their result, certain formulae or values can be used.
case(<booleanExpression>, <Formula for true>, <Formula for false>)
The following rules are available for the Boolean expression:
null == false
leer == false
0 == false
false == false
!true == false
!false == true
1 == true
If logical operators are used for the calculation, false becomes 0 and true
becomes 1. This results in the following:
5 > 0 + 0 > -1 == 2
2.3.6.7. Examples
The calculation call with the function "calculate()" on view pages always has
three parameters:
$ProcessingContext - The current processing context. Value is always fixed.
The current data range - $DC for tables and view pages.
Formula - Formula of choice consisting of the methods and operators
stated above.
Simple addition of two values
Here is a simple example for adding values from data fields.
To address a data field, you can either state its GUID or the name
of the control in single quotation marks.
Example 1
##Parameters to be transferred to the method calculate():
## $ProcessingContext (fixed value)
## $DC
## '<Control name of the first summand>'
## <Operator>
## '<Control name of the second summand>'
$CalcUtil.calculate($ProcessingContext, $DC, 'dataField("integervcontrol1") + dataField("integervcontrol2")')
##Same example but with the data field GUID instead of the control
$CalcUtil.calculate($ProcessingContext, $DC, 'dataField("3BB...5B3") + dataField("C95...950")')
The methods described above can be combined and nested to use values from
different sources (session, request etc.).
Example 2
## Combination of data field and session value.
$CalcUtil.calculate($ProcessingContext, $DC,'dataField("3BB...5B3") + session("calcutil_example")')
## Combination of data field and request value.
$CalcUtil.calculate($ProcessingContext, $DC, 'dataField("floatcontrol02E5") + requestAsNumber("rq_calcUtil")')
## Less than comparison with request value.
#set($term = '(dataField("B5F472ED66DCA878683B52CE8F979F4F1DDA172B") * 2) + session("calcutil_value") <
requestAsNumber("rq_calcUtil")')
$CalcUtil.calculate($ProcessingContext, $DC, $term)
## Case differentiation for request value
#set($term = '(dataField("B5F472ED66DCA878683B52CE8F979F4F1DDA172B") * 2)')
$CalcUtil.calculate($ProcessingContext, $DC, "case(requestAsNumber('rq_calcUtil') <= 100, $term, -1)")
2.3.6.8. Aggregate functions for tables
You can also process values from table columns using "$CalcUtil". The
calculation operations listed in the table below are available for this:
The call of methods for tables always have two parameters:
Table object
Access a table - either via the table name or GUID. These are not
the direct name or GUID of the table control but rather the values
of the attribute "tablerecords" for view tables and "shapedtablebase"
for free layout tables. To identify the values, select
Edit menu / Show elements,
while the page with the table is selected in the
application structure.
Then navigate through the structure of the desired table. You will
find the entry "tablerecords" or "shapedtablebase", respectively.
You can determin the name and GUID of the entry in the respective
Details dialog.
Formel
Formula with any number of levels. Access column values with
row(<column name>) or rowAsNumber(<column name>).
The values are calculated when the page is opened. If the table
has a navigation element and this is used, the values of the
Velocity statements and calculations are not updated because
they the table is reloaded dynamically via AJAX.
If you want to perform table calculations after navigation within
the table, the corresponding VTL Include (or VM) need to also
be reloaded via AJAX. As a workaround, we recommend creating the
table to be calculated in such a way that navigation is not required.
Method
Description
sum
Calculates the sum of the column values from the data that is displayed on the current page.
min
Calculates the minimum of the column values from the data that is displayed on the current page.
max
Calculates the maximum of the column values from the data that is displayed on the current page.
count
Calculates the number of data records shown on the current page.
Please note that the following methods are computation intensive.
If you have a large amount of data, you may encounter corresponding delays.
Method
Description
totalSum
Calculates the sum of the column values of all data records.
totalMin
Calculates the minimum of the column values of all data records.
totalMax
Calculates the maximum of the column values of all data records.
totalCount
Calculates the number of all data records.
Please note: If the table does not contain any data, the methods above
will return the number 0.
Example 2
## Example output of an info text beneath an article table
#set($sum = 'totalSum(table("8E9F10DCB24CBB4B27FF67A3230CE7753521E1B3"), row("integervcontrol3621234C"))')
#set($count = 'totalCount(table("8E9F10DCB24CBB4B27FF67A3230CE7753521E1B3"), row("floatvcontrol256AC41"))')
$CalcUtil.calculate($ProcessingContext, $DC, $count) articles have been ordered with a total value of $CalcUtil.calculate($ProcessingContext, $DC, $sum) €.
Object for accessing a collection of data objects (e.g. the current data record).
Snippet
##Returns the record ID of the current data record as a string
$DC.getRecId()
2.3.12.1. User-defined $DC in emails
Manual initialization of context object $DC (short for
$Loader.getDataCollection()) for using in emails with content generated from
Velocity. With <APP-GUID>, the GUID of the application, which is the
source of the data records to be processed, has to be provided. The following conditions must be met:
Process has to be triggered by a web event
Data record must already exist
Objects (e.g. data fields), that are used in Velocity must be on the target page as a control
Read the value of a control (e.g. value of a view field). Use the name of the control, where the value should be read from, as the parameter.
Within free layout tables tables, use the context object $drRecord instead of $DC.
Read a value from a system data group. The name of the data field that the value
should be read from needs to be stated as a parameter.
Within free layout tables tables, use the context object $drRecord instead of $DC.
##Returns the JobHistory of the data transfers job with the stated GUID
$DataTransferCallable.getJobsHistory("0460E20ACAC15EDDA0E9B62E1F815D5BFD3F9B8F")
##Saves the message with the ID $strMessageId as an EML file in $strDestinationPath.
$ExchangeMessageCallable.saveMessageAsEML($strMessageId, $strDestinationPath)
Object for file operations such as inserting a file into an Intrexx data group.
Snippet
##Deletes the file from the data field
##identified by the GUID and the data record identified by the RecID "1".
$FileHelper.deleteFileFromIntrexx($ProcessingContext, "079A397D11EE732857CD1017C3AC6A55D0D112DA", "1")
2.4.8. Read a single value using a prepared database query (with fallback)
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.
Snippet
#set($statement = $PreparedQuery.prepare($DbConnection, "SELECT <COLUMN> FROM DATAGROUP('<DATAGROUP_GUID>') WHERE <CONDITION>"))
##$statement.setString(1, "Example text")
##$statement.setInt(2, 123)
##$statement.setBoolean(3, true)
#set($result = $statement.executeAndGetScalarValue(<FALLBACK_VALUE>))
$statement.close()
Returns a list of GUIDs of all logged-in users of the current portal. The parameter true/false defines whether anonymous users are included in the result list.
Creates and formats a date according to the specified location. Please
note: The specified location needs to be defined as a portal language in
the portal properties.
Converts an array list into a string, using the default delimiter | and
escape character 0.
To use different delimiter and escape characters, call the function with
additional parameters.
Example
//Using default delimiter and escape characters.
$TextUtil.arrayToString(p_array)
//Using user-defined delimiter and escape characters.
$TextUtil.arrayToString(p_array, "$", "!")
Converts a string into an array, if the string was previously created using
arrayToString(p_myArray) with default delimiter (|) and escape character (0).
Writes the out of office message and sets its status to active.
The text is set for internal and external out of office messages.
Snippet
#set($strMessage = "Out of office till 2010/12/31")
$ExchangeMailboxCallable.setOutOfOfficeMessage($strMessage)
$ExchangeMailboxCallable.setOutOfOffice(true)
Parameters:
$startDate - Start date of the appointment
$endDate - End date of the appointment
$subject - Subject of the appointment
$body - 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.
Parameters:
$lastName - Last name of the contact
$firstName - First name of the contact
$mail - Email address of the contact
$mailbox - The user's mailbox that the contact should be added to. If null, the current users 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.
Parameters:
$start - The tasks start date
$due - The tasks due date
$subject - The tasks subject
$mailbox - The user's mailbox that the task should be added to. If null, the current user's mailbox is used.
#if(condition1)
##code for condition1
#elseif(condition2)
##code for condition2
#else
##code if no condition matches
#end
2.17. For each loop
foreach loop code snippet.
Snippet
#foreach($element in )
#end
2.18. Define a variable
Example
#set( $id = 1)
#set( $userName = "Administrator")
Snippet
#set($variable = aValue)
2.19. Output variable in local format
Outputs a variable in the portal's local format. The variable has to be defined in a ValueHolder.
The following types can be used as the RENDERING_TYPE: integer, datetime, date, time, currency, number, boolean, author
## This is necessary: Prevents the response from having line breaks, unwanted outputs, etc.
$Response.setIgnoreWrite(true)
## You can write your Velocity code here without effecting the response by mistake
## e.g. set a variable
#set($myVar = "Hello client!")
## This may help you: Use a java.util.Map to make JSON formatting easier later.
#set($map = $CollectionFactory.createMap())
## Add everything required into the map with a reliable key.
$map.put("myJSONAnswer", $myVar)
## This is necessary: Format the response so the server delivers JSON.
$Response.setHeader("Cache-Control", "no-cache")
$Response.setHeader("Content-Type", "application/json;charset=UTF-8")
## Format the map to be escaped for the JSON string.
$Response.setIgnoreWrite(false)$JSON.toJSONString($map)