execute script (Integration function)
The execute script (Integration function) function enables the execution of Java code as script.
Parameter a defines the script either directly as Java code (text) or specifies a file path to a text file with such content.
The parameters b, ..., j are optional for the function call. Assigned values can be addressed in the script using the corresponding letters (b, ..., j).
In addition, the script has read access to all variables, lists and maps available in the profile:
Variables can be addressed by the variable name (e.g. VAR_FILENAME).
script.getList ("list_name") returns an entity of the java.util.List type that corresponds to the list with the name list_name.
script.getMap("map_name")returns an entity of the java.util.Map type, which corresponds to the map with the name map_name.
In addition, there is access to DOM objects (type: org.jdom.Document), which can be created with the Lobster_data standard function call SOAP-WebService:
script.getDocument("document_name") returns an entity of the org.jdom.Document type whose content corresponds to the DOM object named document_name.
►NOTE◄ A created DOM entity can be deleted inside the script using the script.deleteDocument("document_name")method or outside the script using the standard Lobster_data function delete DOM object(a).
The return value of the function can be optionally set via return "result" (see examples with and without return).
Parameter
|
Parameter |
Description |
|
a |
Script or (relative) file path |
|
b, ..., j |
Script parameters b, ..., j |
Examples
|
Parameter a |
Parameter b |
Parameter c |
Parameter d |
... |
Parameter j |
Return value |
|
Concatenate strings of parameter b and c from the function call: b+c |
Demo |
Script |
|
|
|
DemoScript |
|
Return the value of the variable VAR_FILENAME (here: demo.txt): return VAR_FILENAME; |
|
|
|
|
|
demo.txt |
|
Call a script provided as a configuration file: ./conf/MyScript.txt ./conf/MyScript.txt
//cast string parameter to long valuelong value=Long.valueOf(b).longValue();switch(value) { case 10: return "yyyyMMdd"; case 20: return "dd.MM.yyyy"; case 30: return "yyyy-MM-dd"; default: return "yyyyMMdd";} |
30 |
|
|
|
|
yyyy-MM-dd |
|
Get a value from a map (in parameter c) or a variable depending on the value in parameter b: if(b.equals("demo")) return script.getMap(c).get("demo"); else return VAR_FILENAME; |
test |
map_demo |
|
|
|
demo.txt |
|
Call a script that formats the DOM object provided as parameter b as a string: ./conf/webservice/DOM_script.java ./conf/webservice/DOM_script.java
//using importsimport java.util.List;import org.jdom.Document;import org.jdom.Element; //method to print jdom Elementprivate void printElement(List children, StringBuffer res, String tab){ for (int i = 0; i < children.size(); i++) { Element child = (Element)children.get(i); res.append(child.getName() +": "+ child.getText() + "\n"); printElement(child.getChildren(),res, tab+"\t"); }} //get jdom Document for DOM name given in parameter bDocument dom = script.getDocument(b);if(dom == null){ return "DOM Object does not exsist";}Element root = dom.getRootElement();List children = root.getChildren(); StringBuffer res = new StringBuffer();//call method from aboveprintElement(children, res, "");//returns String as Filter resultreturn res.toString(); |
myDOM |
|
|
|
|
[object as string] |