Handling workflow from automation script

If you need to handle workflows (start, stop, route, etc.) from an automation script you can use the following two Maximo API classes: WorkFlowService and WFInstance. Here are few examples.

The WorkFlowService.initiateWorkflow metod can be used to start a workflow:

from psdi.server import MXServer
# get the workflow service
wfSrv = MXServer.getMXServer().lookup('WORKFLOW')
# start the workflow
wfSrv.initiateWorkflow("MYWF", mbo)

To stop an active workflow you can use WFInstance.stopWorkflow method:

from psdi.server import MXServer
# get the workflow service
wfSrv = MXServer.getMXServer().lookup('WORKFLOW')
# get active instances for the current mbo
wfSet = wfSrv.getActiveInstances(mbo)
# stop the first workflow instance
wfSet.getMbo(0).stopWorkflow("Stopped")

To route a workflow I have used the WorkFlowService.completeAssignment method. Here it is a little more complex since we first have to get the right WFAssignment record to the current Mbo and user.

from psdi.mbo import SqlFormat
from psdi.server import MXServer

def getMboAssignments(mbo, personid):
  sqf = SqlFormat(mbo, "ownertable=:1 and wfassignment.ownerid=:2 and assigncode=:3 and assignstatus='ACTIVE'")
  sqf.setObject(1, "WFASSIGNMENT", "OWNERTABLE", mbo.getName())
  sqf.setLong(2, mbo.getUniqueIDValue())
  sqf.setObject(3, "WFASSIGNMENT", "ASSIGNCODE", personid)
  assignSet = mbo.getMboSet("$CURMBOASGN", "WFASSIGNMENT", sqf.format())
  assignSet.reset()
  return assignSet

wfSrv = MXServer.getMXServer().lookup('WORKFLOW')
wfAsSet = getMboAssignments(mbo, mbo.getUserInfo().getPersonId())
if not wfAsSet.isEmpty():
  wfAs = wfAsSet.getMbo(0)
  wfSrv.completeAssignment(wfAs, "Approved by script", True)
  

Handling workflow from automation script

2 thoughts on “Handling workflow from automation script

  1. Hello there, Bruno.
    I tried to use your “stop an active workflow” example, but did not work. I got error “AttributeError: ‘NoneType’ object has no attribute ‘stopWorkflow'”.
    After researching I tried something and got the following, this worked:

    def fecharWorkflowAtivo(curMbo):
    wfAssignmentSet = curMbo.getMboSet(“$wfassignment”, “WFASSIGNMENT”, “ownertable=’WORKORDER’ and ownerid=:workorderid and assignstatus=’ACTIVE'”)
    wfAssignment = wfAssignmentSet.getMbo(0)
    if wfAssignment is not None:
    wfAssignment.close()

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top