Friday, February 13, 2015

Use an automationscript in a Condition node of a Workflow

Use an automationscript in Maximo to calculate the outcome of a condition node in Maximo. 

I have a record with zero or more child records. e.g. a  Workorder with Task workorders. I also have a workflow and I want the Workorder only to be able to go in to the workflow if the Tasks all have the same Location.

Whith the condition nodes in Workflow you can set an Expression. But how can I loop through task workorders within an expression? That would make a difficult expression. Looping through records (and doing a lot of other stuff) is much easier in an automation script. How can I use the best of both worlds?

So I need to call an automationscript from a workflow. First I set up my basic workflow. For more information about that, see one of my previous posts, with information on setting up a basic workflow.

My workflow:

When starting the workflow, the check is performed, and when not satisfactory a message is shown to the user and the workflow is stopped.

The condtion now needs to call my automation script.

Create the script on a Custom Condition Launchpoint:

I want the script to run on the workorder object:

Name the script:

Paste in the source code for the script and click the [Create] button

Source code script:

print "Start CHECKTASKLOC script";

from psdi.mbo import Mbo;
from psdi.server import MXServer;

Date: 20150211
Author: G.N. Zomerdijk

Purpose of script:
Check if the location on all tasks are the same

The script will be run from a condition node in the Workflow

Custom Condition Launchpoint: WOFLOW on WORKORDER object

Useage in Workflow:
Condition Node with title: CHECKTASKLOC:WOFLOW   That is the <script name>:<launchpoint name>
Custom Class: Y

For reference when we want to use it in a Condition:
Create the following condition:
Condition: TEST
Condition class:

Expression should hold launch point information: <script name>:<launchpoint name>

evalresult is returned, is an internal variable, no need to define it as variable in automationscript application.

#set values for used variables
evalresult = True;
loc = "";

#Loop through the PRLINES
tasksFromWOSet = mbo.getMboSet("WOACTIVITY")
tasksFromWO = tasksFromWOSet.moveFirst()

while tasksFromWO is not None:    
    if (loc != "" and loc != tasksFromWO.getString("LOCATION")):
        evalresult = False;
        loc = tasksFromWO.getString("LOCATION");

    #get the next task
    tasksFromWO = tasksFromWOSet.moveNext();

print "evalresult: " + str(evalresult);

print "End CHECKTASKLOC  script";

The script returns a True or a False. This is done by setting the evalresult variable. See the code above for more detailed information.

Now in the workflow we can run the script by modifying the Condition Node.

Condition Node with title: CHECKTASKLOC:WOFLOW   That is the <script name>:<launchpoint name>

Custom Class: Y

After clicking OK I get:

Click OK in the error and Click OK again in the condition node. Do not know why the error occurs, but the second time around it is validated. Maybe because the Custom Class is checked, and only at the second run the Expression is validated as a Custom Class.

The workflow looks like this now:

Save the Workflow.

Next I associate the Workflow with the Workorder (WOTRACK) application

I only add support for the WOTRACK application, so deselect the rest of the application and click [OK]

Next Validate, Enable and Activate the process:

Create a workorder, with 3 task workorders.

On one of the tasks change the location from FOORBAR to FOOBAR2 and save the workorder.

Now I want to route the workorder in the workflow, but the button is grayed out... 

I go back to the workflow and go in the Select Action menu to the "Edit Workflow GO Buttons" 

There I add the Process Name to the existing Application row.

I save the workflow and open my workorder again.
Still grayed out... I decide to now logout maximo and log back-in.
Open the workorder again and the button is now available!

And now I get the message:

I change location on the second task to match the other tasks, save the workorder and hit the workflow button again.

Now the record is routed in the workflow: 


For more info about automationscripting I used the pdf from this page:

For more information about workflow I used this "Workflow Implementation Guide":