Groovy-scripts
In addition to external JPL scripts, it is now also possible to execute Groovy scripts via the d.3 server interface.
In a Groovy script file, the d.3 interface is available as a field variable d3 and can be used directly.
d3.log.info("Groovy-Script started!")To register the type of the predefined field d3 in a development environment so that type validations, command completions etc. can work, the following two lines should be included at the beginning of a script.
import com.dvelop.d3.server.Document
import com.dvelop.d3.server.core.D3Interface
import com.dvelop.d3.server.exceptions.D3Exception
D3Interface d3 = getProperty("d3");
String scriptName = getClass().getName()
d3.log.info("Groovy-Script started!")
// d.3 User which executes the update of documents
String scriptUser = "d3_groovy"
final def maxRows = 3
//Einzelne Dokumente/Akten anhand der ID
def resultSet = d3.sql.executeAndGet("select doku_id from firmen_spezifisch where kue_dokuart = 'DTEST' and dok_dat_feld_1 = 'oldValue'", maxRows)
resultSet.each{
try {
d3.log.info (scriptName + "> Updating document with ID " + it.doku_id)
//Get document object of doc id
Document myDoc = d3.archive.getDocument(it.doku_id, scriptUser)
//Set new value
myDoc.field[1] = "newValue"
//Update metadata without triggering hook entrypoints
myDoc.updateAttributes(scriptUser, true)
} catch (D3Exception e) {
d3.log.error(scriptName + "> Error updating meta data " + e.getMessage())
}
}Using Groovy-classes and Java-libraries in scripts
The Groovy script directory "ext_groovy" and the defined Groovy Hook directories are added to the CLASSPATH when executing a script so that classes from other Groovy-scripts can be used in the executing script. Moreover, Classpath-files are also supported for scripts (file name: "<script name>.classpath") The included paths (e.g. absolute path of a JAR-file) are also added to the classpath to allow you to use these resources in the script.
Example: The JavaMail API (javax.mail.jar) is to be used in a script ../ext_groovy/myScript.groovy. For this purpose, the absolute path of the JAR-file is entered in a Classpath file with the same name ../ext_groovy/myScript.classpath:
Sample file content: D:\downloads\java\ext_jars\javax.mail-1.5.6.jar
Starting scripts controlled by timers
If you want a script to be started automatically and on a timer-controlled basis, rather than interactively, this can be specified as the sixth command line parameter of a server process in the d.3 process manager. The target entry in d.3 process manager will then appear similar to the following:
..\d3odbc32.exe haupt "" d3_server d3_server D3P ext_groovy/myScript.groovy