Maximo Open Forum

 View Only

 Automation Script Assistance

  • Administration
  • Customizations
  • Everything Maximo
  • Work Management
Peter McDonald's profile image
Peter McDonald posted 06-15-2022 23:59
Hi Folks

Can someone help with an automation script please

I'm using a Push Button on a mobile enabled app to change the status of a work order but I need to check if a worklog entry has been added, and if it hasn't display a message accordingly (I can do that bit) otherwise allow the change to occur  I can happily do it in workflow using the following
exists (SELECT 1 FROM WORKLOG WHERE recordkey = :wonum and logtype = 'REASSIGN' and CREATEBY = :&PERSONID&)
as a condition but have no idea how to incorporate this into an existing automation script (below)

from psdi.mbo import MboConstants
from psdi.server import MXServer
currentDate = MXServer.getMXServer().getDate();
status = mbo.getString("status");
if mbo.getString('orgid') == 'SYD':
mbo.changeStatus('COMP', currentDate, 'Set COMPLETE', MboConstants.NOACCESSCHECK | MboConstants.NOVALIDATION_AND_NOACTION);
mbo.setValue('LEAD', 'xxx');
mbo.getThisMboSet().save();

Thanks in aadvance

Cheers
Steven Shull's profile image
Steven Shull
Be extremely cautious utilizing NOVALIDATION_AND_NOACTION. I've written thousands of automation scripts for customers and I have probably used this less than 5 times on anything out of the box. Are you sure this is needed? If so, why? Without looking at the underlying logic here, I can't tell you what issues will occur. But there is a lot of Maximo logic on Work Order status changes, especially on completion, that you may be breaking by doing this. As an example, if that WO was a PM we update the last completion date on the PM. Based on organization settings, we potentially record asset history and/or delete inventory reservations. You should almost never suppress validation or action on out of the box attributes. 

You want something like below. When you open a set you can either utilize a relationship (something defined in database configuration) or establish your own where clause like I did in this example utilizing your criteria. While you may be a single site today (or wonum might be unique based on a prefix), you should always write your queries with the proper joins to child tables so that a new site in the future doesn't break all of your existing criteria. So I added the class & siteid filters that we utilize to join WORKORDER to WORKLOG normally.

The service.error() throws an error message that is defined in Database Configuration. You'll have to define what you want that to be and then update the message group & message key variables.

from psdi.server import MXServer
currentDate = MXServer.getMXServer().getDate()
status = mbo.getString("status")
if mbo.getString('orgid') == 'SYD':
    workLogSet=mbo.getMboSet("$EMXWORKLOG","WORKLOG","exists (SELECT 1 FROM WORKLOG WHERE recordkey = :wonum and class=:woclass and siteid=:siteid and logtype = 'REASSIGN' and CREATEBY = :&PERSONID&)")
    if workLogSet.notExist():
        service.error("emx","myErrorMessage")
    mbo.changeStatus('COMP', currentDate, 'Set COMPLETE', mbo.NOACCESSCHECK | mbo.NOVALIDATION_AND_NOACTION)
    mbo.setValue('LEAD', 'xxx')
    mbo.getThisMboSet().save()​