MD Link Jython code interacts with the MD Link engine through an object called engine. Below are the fields and functions available on that object from within a Custom Event. To call any of these from your script, you must preceed the name of the field or function with a reference to engine - for example:
print engine.solnId
An engine object will be available to Jython scripts in all of a Custom Event's scripts - 'Load', 'Run', and 'Unload'. However, some of the fields and functions described below are only available from within certain scripts - for example from the 'Run' script, but not the 'Load' or 'Unload' scripts. For each field or function which has such limited availability, this is documented below. If an attempt is made by your Jython code to access a field or function that is not available in the current context, then an exception will be raised. This exception will by default appear in the logs, and will interrupt the control flow of your script. The exception will contain an error message noting the cause.
Read-only property. This is the version of MD Link that is currently running (major and minor version numbers only) encoded as an integer such that, for example:
4.3.14.2 becomes 4030000
5.12.5 becomes 5120000
Read-only property. This is the ID of the enclosing event - for example, E3.
eventVars (type: python dictionary object)
This is a python dictionary object that allows the Jython coder to store variables in a place where they are accessible between the 'Load', 'Run', and 'Unload' scripts of their event. For example, one could add the following code to their 'Load' script:
engine.eventVars['foo'] = 42
And then the following code to their 'Run' script:
print engine.eventVars['foo']
and the 'Run' script would print '42' to the logs.
logdebug (type: python file-like object)
Read-only property. This is a Jython output file stream that is redirected to MD Link's debug-level logs. You can use it as part of a print statement like this:
print >> engine.logdebug, 'Some debug info.'
loginfo (type: python file-like object)
Read-only property. This is a Jython output file stream that is redirected to MD Link's info-level logs. You can use it as part of a print statement like this:
print >> engine.loginfo, 'Some info-level info.'
A simple print statement like this:
print 'Some info-level info'
will accomplish the same thing. This field is just provided for convenience in some programming scenarios.
logwarn (type: python file-like object)
Read-only property. This is a Jython output file stream that is redirected to MD Link's warning-level logs. You can use it as part of a print statement like this:
print >> engine.logwarn, 'Some warning info.'
logerror (type: python file-like object)
Read-only property. This is a Jython output file stream that is redirected to MD Link's error-level logs. You can use it as part of a print statement like this:
print >> engine.logerror, 'Some error info.'
outputDom (type: Java DOM object - i.e. org.w3c.dom.Document)
This is the output message of the current event firing. It is a DOM object, like inputDom for task executions. The value of this field will be None by default; it is the responsibility of the Custom Event implementer to create a useful document object and point this field at that document. Then, you must call fireEvent(), to let the engine know to pick up this document and begin the message's processing down through the solution.) For example:
engine.outputDom = util.makeXMLDocument('EventData')
Only a single XML document (and thus, message) at a time can be specified with this field.
Read-only property. This is the ID of the solution of which this event is a part, as assigned by the engine. eg. SOLN3.
solutionFilename (type: string)
Read-only property. This is the absolute filename of the solution file of which this event is a part.
Will cause the current script to fail immediately. Control will not return to the calling Jython code. An error message will be logged.
If this is called from the 'Load' script, then the solution will refuse to load. If it is called from the 'Run' script, then the event's run thread will exit. If it is called from the 'Unload' script, nothing will happen except for the error message logged.
message - optional. This message string will show up in the log message that results from this call.
Available only from the 'Run' script. Instigates an event firing with the XML document currently in outputDom.
This method causes the Jython script to exit immediately. If this is called from the 'Run' script, then the event's run thread will exit.
string getVarVal(string variablename)
Gets the value of a variable. This could be a solution or global variable. If there are both solution and global variables defined with the name supplied, then the value of the solution variable will be returned.
Do not include $ or ${} to reference the variable name, as you would when referencing variables in elsewhere in the product.
If the given variable name does not exist, an exception will be raised.
Example:
engine.getVarVal('sender')
might return "LAB".
Given a string containing references to variables, this function substitutes the variable names with their values. Each variable name can be either a solution or global variable. If there are both solution and global variables defined with the name supplied, then the value of the solution variable will be returned.
Unlike getVarVal(), for this function you will need to include $ or ${} to reference the variable names, as you would when referencing variables in elsewhere in the product.
Also unlike getVarVal(), if the given variable name does not exist, then the original variable reference will appear in the return value unmodified. No exception will be raised by this case.
Example:
engine.subVarVals('sender: ${sender}, receiver: ${receiver}')
might return "sender: LAB, receiver: DATABASE"