Skip to content
Handling workflow from automation script

Handling workflow from automation script

January 25, 2023

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)
  


Share this:
Twitter Facebook LinkedIn