Sample Jython Script

This sample Jython script shows the basic attribute access techniques without the use of parameter metadata. Inputs and outputs are hard-coded in the source code.

The following script example demonstrates how to read an attribute from the input object (workorder), how to read a specification attribute from the input object, how to set an attribute in the input object, and how to read and write a specification attribute defined in the workflow instance. If your workorder or workflow instance does not have specification attributes set, for example SPEED or MATERIAL, then the sets returned by scriptHome.getMboSet and wfinstance.getMboSet will be empty, and no values are printed. The action log displays the following when the script runs:
  • Work order identifier: TEST1
  • Speed = 35 MPH
  • New owner is WILSON
  • Material: BRASS
  • New Material: COPPER
#Get and display the workorder name
wonum = scriptHome.getString("wonum")
print "Work order identifier: ", wonum

#Get and display the value for the WO spec SPEED (if it exists)
woSpecSet = scriptHome.getMboSet("$SPECS", "WORKORDERSPEC", "assetattrid='SPEED'")
emptySet = woSpecSet.isEmpty()

if emptySet == 0:
   woSpec = woSpecSet.getMbo(0)
   speed = woSpec.getInt("numvalue")
   units = woSpec.getString("measureunitid")
   print "Speed = ", speed, units

#Modify the owner attribute of the object
scriptHome.setValue("owner", "WILSON")
owner = scriptHome.getString("owner")
print "New owner is " , owner

#Get workflow instance spec for attribute MATERIAL. Display the value, then modify it
instSpecSet = wfinstance.getMboSet("$INSTSPECS", "WFINSTANCESPEC", "assetattrid='MATERIAL'")
emptySet = instSpecSet.isEmpty()

if emptySet == 0:
   instSpec = instSpecSet.getMbo(0)
   material = instSpec.getString("alnvalue")
   print "Material: ", material  
   instSpec.setValue("alnvalue", "COPPER")
   material = instSpec.getString("alnvalue")
   print "New Material: ", material