Tips & Tricks - Importing Files
Using "g_dgFile," you can import any files as attachments into an Intrexx application. In this example, a time-controlled process is used that searches a directory for .png files using a Groovy script and writes them as attachments to any application.
You can download the sample application, process, and four PNG image files here. Unzip the downloaded file. Included are the "bilddateien-png" directory, which contains four PNG files you can use for testing, and the file "help.2.tipps-tricks-dateien-importieren-app-process.zip." You can import these as usual.
Here you'll find more information about the "g_dgFile" class.
The sample application has a data group with a primary key in the form of a GUID. This data type can be selected when creating a new data group.
There is also a file data field in the data group.
The overview page contains a table that is linked to the data field from the data group.
The sample process contains a timer with the corresponding timer event handler and a Groovy action. You can open the Groovy action's properties dialog by double-clicking it. There, switch to the " Script " tab and open the Intrexx Editor. Here is the following Groovy script.
import groovy.io.FileType
// Connection to portal data base
def conn = g_dbConnections.systemConnection
// Source direction
def path = 'c:/img/'
// the source directory should be searched in a depth of three subdirectories
// for .png and .PNG
new File(path).traverse(
type:FileType.FILES,
nameFilter:~/.+\.(?i)png$/,
maxDepth:3
){ pngFile ->
// in the Closure, each .PNG file is available as java.io.file
// in the variable pngFile
// for each file a record is created, to which the files are
// will be added later as an attachment
// the GUID is the GUID of the data group from the application
def id = newGuid()
g_dbQuery.executeUpdate(conn, "INSERT INTO DATAGROUP('B78B96ADA0A81927B7ED013946ED7DC0331CCEC2') (STRID) VALUES (?)") {
setString(1, id)
}
// now the file can be attached to the record, where
// the GUID corresponds to the GUID of the file data field
// the source file is moved, i.e. it is no longer located afterwards
// in the source directory
g_dgFile.move(guid: "185C69FFD1D97C10F3C09BC1D0D2C1633BEAE039", id: id, file: pngFile, deleteAlways: false, triggerWorkflow: false)
}
Replace the path "c:/img/" with the name of the directory containing the images you want to import. Of course, other file types, such as PDF files, can also be imported. The script must then be modified accordingly.
The directory containing the files must be writable by the portal service provider. This is something to keep in mind, especially when it comes to network drives. If a directory contains more than just PNG files, the file extensions must be checked.
Replace the GUIDs for the data group and data field in the Groovy script with the corresponding GUIDs from your application. You can select your target application in the Application Structure section and find the corresponding GUIDs there. Then close the editor and the Groovy action's properties dialog by clicking "OK." Save the process and start the timer from the "Edit" main menu.
Here you can see the files in the target application.





