Functions for Python(3.1)

The following functions apply to Python agents in both real-time and batch workflows.

This section includes the following:

  • UDR Related Functions
  • Debug Related Functions
  • MIM Related Functions
  • Misc Functions
  • Dynamic Functions
  • Timeout Functions
  • Log Related Functions

UDR Related Functions

udrCreate

This function creates a new UDR of the specified type, and can take keyword arguments to set its fields.

def udrCreate(typename, **kwargs)

Parameter

Description

typenameA defined UDR type
**kwargsKeyword arguments to set the specified fields
ReturnsA UDR of the type specified

Example - udrCreate

#
# The following shows six different ways of creating UDRs
#

from ultra.MyFolder.MyUltra import MyUDR

myudr1 = MyUDR(field1=33, field2=88)

myudr2 = MyUDR()
myudr2.field1 = 33
myudr2.field2 = 88

myudr3 = udrCreate(MyUDR, field1=33, field2=88)

myudr4 = udrCreate(MyUDR)
myudr4.field1 = 33
myudr4.field2 = 88

myudr5 = udrCreate("MyFolder.MyUltra.MyUDR", field1=33, field2=88)

myudr6 = udrCreate("MyFolder.MyUltra.MyUDR")
myudr6.field1 = 33
myudr6.field2 = 88

udrIsPresent

 This function returns True if the UDR field is present.

def udrIsPresent(udr, attr)

Parameter

Description

udrThe UDR
attrThe attribute name
ReturnsTrue if the UDR field is present.

Example - udrIsPresent

if udrIsPresent(myudr, 'field1'):
    debug("The optional field 'field1' is present") 

udrUnsetPresent

 This function marks an optional attribute for a UDR as not present.

def udrUnsetPresent(udr, attr)

Parameter

Description

udrThe UDR
attrThe attribute name
ReturnsNothing

Debug Related Functions

debug

This function prints the supplied object to the output target specified in the Execution tab of the Workflow Properties dialog. 

If Event is selected, the output is shown in the Workflow Monitor.

def debug(obj)

Parameter

Description

obj

The object to write to debug output. The object can be of any type.

Note that printing a UDR type will dump all the field values, which may be a large amount of data. Similarly, the debug output for a table, map, list or bytearray type may be very large.

The output is the string representation of object.

ReturnsNothing

isDebugEnabled

This function states if debugging has been enabled for the workflow. A debug event is only sent if isDebugEnabled returns True.

def isDebugEnabled()

Parameter

Description

ReturnsTrue or False depending on if debug is enabled or not

MIM Related Functions

mimGet

This function returns the value of a MIM resource available in the workflow.

def mimGet(category, mimResourceName)

Parameter

Description

categoryThe name of the agent or workflow that owns the MIM resource
mimResourceNameThe name of the MIM resource whose value is to be returned
ReturnsThe MIM value.

Example - mimGet

mimGet('Workflow', 'Batch Count') # Retrieving a MIM resource owned by the workflow.
mimGet('Python_1', 'Source File Count') # Retrieving a MIM resource owned by the agent 'Python_1'.

mimSet

This function assigns a value to a user defined MIM resource. The function may be called at any time. Note that it is the responsibility of the user to make sure the MIM value is available in accordance with the specified assigned type.

def mimSet(name, value)

Parameter

Description

nameThe name of the MIM resource to assign a value
valueThe value to assign, which must match the published MIM type
ReturnsNothing

Example - mimSet

mimSet('My MIM', 88)

Misc Functions

abort

This function stops the workflow, and logs a user defined message to the System Log.

def abort(message)

Parameter

Description

messageThe message that is sent to the System Log when the workflow is aborted
ReturnsNothing

Example - abort

abort('The processing failed, aborting this workflow!')

wfStop

This function stops a running workflow. wfStop produces a single stop signal and does not wait for the workflow to stop. If it succeeds in stopping the workflow, the stop is registered in the System Log.

def wfStop(wfName, immediate=True)

Parameter

Description

wfNameYou must provide the name of the workflow to be stopped.
immediateFor a real-time workflow, the immediate flag has no significance. For a batch workflow, when immediate=True, the function stops the currently handled batch; when immediate=False, the currently handled batch is run and then the workflow stops.
ReturnsIf the command is successful the value is None. Otherwise, a text message is returned.

Example - wfStop

wfStop('Default.MyWorkflow.workflow_1')

isStopped

This function states if the workflow has been stopped.

def isStopped()

Parameter

Description

ReturnsTrue or False depending on if workflow has been stopped or not

Example - isStopped

if not isStopped():
    debug('Not stopped yet')

Dynamic Functions

dynamicFieldGet

This function retrieves the stated dynamic field from the workflow table. The returned value can either be a boolean, an integer, or a string.

def dynamicFieldGet(category, name)

Parameter

Description

categoryThe cateogry of the dynamic field
nameThe name of the dynamic field
ReturnsThe value of the selected dynamic field

Example - dynamicFieldGet

dynamicFieldGet('Control', 'Filename')

Log Related Functions

logInformation

This function logs a message string to the System Log of type information.

def logInformation(message)

Parameter

Description

messageA message appearing in the log
ReturnsNothing

logWarning

This function logs a message string to the System Log of type warning.

logWarning(message)

Parameter

Description

messageA message appearing in the log
ReturnsNothing

logError

This function logs a message string to the System Log of type error.

def logError(message)

Parameter

Description

messageA message appearing in the log
ReturnsNothing

logException

This function logs the current exception to the System Log.

def logException()

Parameter

Description

ReturnsNothing

Example - logException

try:
    some_function()
except:
    # Log exception to the System Log instead of aborting the workflow.
    logException()

formatException

This function formats the current exception and returns the string.

def formatException()

Parameter

Description

ReturnsThe current exception formatted as a string

Â