Intrexx Xtreme 4.5 provides new opportunities to users with the integration of the object-oriented scripting language ‘Groovy’. Certain workflows required a lot of development or were even impossible to setup but with Groovy they can now be created quickly and easily.
In the example described below we will show you how to develop a task management application with only a few lines of code.
The task management application in this workshop will count and manage all activities for a customer. Instead of using JavaScript (oTable.aRecIds.length) or a table attribute (show-totalcount) you may participate from the advantage that the calculated amount is being stored to the database. That means the amount is not only available when the page with the activity-table is being opened, it can also be displayed on other pages in your portal as a ‘view field’.
Add two new data groups
Customers and
Activities within the Application Designer. The data group
Activities has to be a sub-data group of
Customers.
Data group Customers requires the following fields:
- Customer (string)
- Customer Number (string)
- Amount of Activities (integer)
Data group activities requires the following fields:
- Activity Title (string)
- Activity Description (longtext)
- Status (string)
Create an input page for each data group, to allow the entry of new customers and activities.

Please add a view page for customers. On this page we’ll show a view table with all activities of the selected customer (Option Show Depending Rows). Now create a button which will jump straight to the input page activities.
On the main page of the application we’ll need a view table of the data group customer with the fields customer number, customer and amount of activities. Finally add the magnifying-class button which will jump to the view page customer.
The application structure should look something like that:
Notice: Please ensure that the names used for the data groups and fields are identical with the wording used in the script.
Please switch to the Process Manager and create a new process. Add three data group actions: add, modify and delete activities. Copy the following code into the groovy script action which will always be executed when a new task is being added.
//define system database
l_conn = g_dbConnections.systemConnection
def l_vhFkLid = g_record["1F03F15B07902ECD5FB3ACBFA3B1DCCFD426805A"] // datafield (FK) (S) FKLID
def l_strStatus = "Closed"
//calculate amount of open activities
def l_stmtTaskCount = g_dbQuery.prepare(l_conn, "SELECT COUNT(LID) FROM XDATAGROUP6C44BD63 WHERE FKLID = ? AND STR_STATUS <> ?")
l_stmtTaskCount.setInt(1, l_vhFkLid)
l_stmtTaskCount.setString(2, l_strStatus)
def l_rsTaskCount = l_stmtTaskCount.executeQuery()
//Refresh amount of activities
def l_stmtTaskCountUpdate = g_dbQuery.prepare(l_conn, "UPDATE XTABLE4CF835F8 SET L_ANZAHLAUFGABEN = ? WHERE LID = ?")
l_rsTaskCount.each
{
l_stmtTaskCountUpdate.setInt(1, it.value(1))
l_stmtTaskCountUpdate.setInt(2, l_vhFkLid)
l_stmtTaskCountUpdate.executeUpdate()
}
Notice: In the script the status of an activity is compared to ‘closed’ to consider only new and open activities. If you are using different wording please make relevant changes to the script (Variable 1_strStatus).
On deletion of an activity please use the following script:
//define system database
l_conn = g_dbConnections.systemConnection
def l_vhFkLid = g_record["1F03F15B07902ECD5FB3ACBFA3B1DCCFD426805A"] // datafield (FK) (S) FKLID
def l_vhLid = g_record["AFE579186D7B88511172FB84705F2867B5BE9985"] // datafield (PK) (S) ID
def l_strStatus = "Closed"
//Calculate amount of activities that are not closed, not considering the just deleted record
def l_stmtTaskCount = g_dbQuery.prepare(l_conn, "SELECT COUNT(LID) FROM XDATAGROUP6C44BD63 WHERE FKLID = ? AND STR_STATUS <> ? AND LID <> ?")
l_stmtTaskCount.setInt(1, l_vhFkLid)
l_stmtTaskCount.setString(2, l_strStatus)
l_stmtTaskCount.setInt(3, l_vhLid)
def l_rsTaskCount = l_stmtTaskCount.executeQuery()
// Refresh amount of activities
def l_stmtTaskCountUpdate = g_dbQuery.prepare(l_conn, "UPDATE XTABLE4CF835F8 SET L_ANZAHLAUFGABEN = ? WHERE LID = ?")
l_rsTaskCount.each
{
l_stmtTaskCountUpdate.setInt(1, it.value(1))
l_stmtTaskCountUpdate.setInt(2, l_vhFkLid)
l_stmtTaskCountUpdate.executeUpdate()
}
The only difference in the script is that the current record shall not be counted as it has just been deleted. (AND LID <> ?).
The process should look like that:
Save the process on the server.
It will calculate and update the amount of activities on every adding and deletion of an activity that has not been closed.
Based on this application more features can be easily added e.g. next activity that is due.
General information about Groovy can be found at
http://groovy.codehaus.org/.
How easy you can integrate Groovy into Intrexx can be read in our manual ‘
Scripting with Groovy’.