Maximo

Maximo

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Automation Scripting

    Posted Wed June 08, 2022 05:09 AM
    I'm after some help with creating an automation script that will transfer the workorder actfinish date to a custom field on the associated location record.
    I'm a complete novice at scripting and have been researching on the web with little success.
    I've created a button on the workorder screen which can be pressed to run the update script, I'll probably replace this to run when the workorder status changes in the future.


    So far i've got this far but it doesn't seem to like using LOCATIONS.VISINSPDATE


    from psdi.mbo import MboConstants

    # Set the locations last visual inspection date the same as actaul finsih date of the workorders based on the ex inspection type when a work order is closed if it is gretaer than the current value
    if ((LOCATIONS.VISINSPDATE is None or LOCATIONS.VISINSPDATE > actfinish) and WORKORDER.WO11 == 'VISUAL INSP OK'):
    mbo.setValue("LOCATIONS.VISINSPDATE",actfinish);
    # Set the locations last visual inspection date the same as actaul finsih date of the workorders based on the ex inspection type when a work order is closed if it is gretaer than the current value
    elif ((LOCATIONS.DETINSPDATE is None or LOCATIONS.DETINSPDATE > actfinish) and WORKORDER.WO11 == 'DETAILED INSP OK'):
    mbo.setValue("LOCATIONS.DETINSPDATE",actfinish);
    else:

    ------------------------------
    Richard White
    ------------------------------

    #AssetandFacilitiesManagement
    #Maximo


  • 2.  RE: Automation Scripting

    Posted Wed June 08, 2022 06:53 AM

    Would you need to transfer the data immediately?
    A very simple solution is an escalation, preferably run outside of peak hours so you also avoid the risk of users getting the "the record has been updated" error message and losing their changes.

    Use two escalation points, one for VISINSPDATE and one for DETINSPDATE. Add your logic to the Escalation Point Condition, and have the Escalation itself evaluate on status and other common conditions you might require.
    For each escalation point, create an action looking something like this, using the default relationship from WORKORDER to LOCATIONS, and obviously subbing for your own fields - I used an OOTB datetime field for this screenshot.

    Works wonders and easy to maintain and schedule.



    ------------------------------
    Henrik Christiansen
    ------------------------------



  • 3.  RE: Automation Scripting

    Posted Thu June 09, 2022 01:22 AM
    Thanks Henrik
    I've tried your idea and i have got it to work.

    I am still looking at how to do this with scripting, more as a learning exercise for me.
    I think scripting is really powerful but it not easy to understand and I can't find much in the way of online resource aimed at my limited experience in scripting.

    ------------------------------
    Richard White
    ------------------------------



  • 4.  RE: Automation Scripting

    Posted Wed June 08, 2022 11:11 AM
    Edited by System Admin Wed March 22, 2023 11:55 AM
    Richard, this should be pretty close to what you're trying to do...

    A couple of key concepts...
    1. You *almost* always want to access Maximo data using the mbo.get[Something] set of methods (getString(), getBoolean(), getDate(), getInteger(), etc). In this case mbo is the current Work Order record, but it could just as easily be a PO or something else.You can also find yourself in situations where you're referencing an MBO using another variable name like wo or po, and the same set of methods should work there too.
    2. Relationships are your friend. In this case the WO->Location relationship will never return more than one value, so you can simply reference the relationship in the getDate() methods: mbo.getDate('LOCATIONS.VISINSPDATE'). If your relationship has the potential to return more than one row you'll typically be using mbo.getMboSet([relationshipname]) and walking through the results one at a time.
    3. Where this requirement gets a little bit more complex is in comparing dates. To do this you need some of the core Java functionality.

    from java.util import Calendar
    
    visinsp = mbo.getDate('LOCATIONS.VISINSPDATE')
    detinsp = mbo.getDate('LOCATIONS.DETINSPDATE')
    actfinish = mbo.getDate('ACTFINISH')
    
    visinspcal = Calendar.getInstance()
    visinspcal.setTime(visinsp)
    detinspcal = Calendar.getInstance()
    detinspcal.setTime(detinsp)
    actfinishcal = Calendar.getInstance()
    actfinishcal.setTime(actfinish)
    
    # Set the locations last visual inspection date the same as actaul finsih date of the workorders based on the ex inspection type when a work order is closed if it is gretaer than the current value
    if ((visinsp is None or visinspcal.after(actfinishcal)) and mbo.getString('WO11') == 'VISUAL INSP OK'):
      mbo.setValue("LOCATIONS.VISINSPDATE", actfinishcal.getTime())
    # Set the locations last visual inspection date the same as actaul finsih date of the workorders based on the ex inspection type when a work order is closed if it is gretaer than the current value
    elif ((detinsp is None or detinspcal.after(actfinishcal)) and mbo.getString('WO11') == 'DETAILED INSP OK'):
      mbo.setValue("LOCATIONS.DETINSPDATE", actfinishcal.getTime())​


    ------------------------------
    Tim Ferrill
    Solutions Consultant
    Intelligent Technology Solutions
    tferrill@webuildits.com
    www.webuildits.com
    @tferrill/@webuildits
    ------------------------------



  • 5.  RE: Automation Scripting

    Posted Thu June 09, 2022 01:18 AM
    Thanks for the pointers Tim, much aprreciated.

    I'd used the wrong relationship in my original attempt so changing LOCATIONS.VISINSPDATE to LOCATION.VISINSPDATE has helped resolve one issue.

    I'm still stuck on the date comparrision.
    I thnk this is because the LOCATIONS.VISINSPDATE is empty and it throws an error,
    I might have to change it so it
    1. Checks for Nulls first and populate with the date.
    2. Check if any exisiting dates are newer than the date being transfered.

    Now iI know it's possible and i'm not a million miles off.

    Thanks again

    ------------------------------
    Richard White
    ------------------------------