Maximo

Maximo

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

 View Only
Expand all | Collapse all

Working example of asynchronous automation script? (7.6.1.2)

  • 1.  Working example of asynchronous automation script? (7.6.1.2)

    Posted Wed September 09, 2020 08:35 PM
    Edited by System Admin Wed March 22, 2023 11:51 AM

    Maximo 7.6.1.2:

    Would anyone have a working example of an asynchronous automation script (Jython) that they could share?
    I haven't come across one yet.

    Docs: Adding scripts that run as asynchronous jobs
    Related post: Run asynchronous tasks from automation scripts (new in 7.6.1.2?)

    Cheers!


    #Maximo
    #AssetandFacilitiesManagement


  • 2.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Thu September 10, 2020 06:30 AM
    Hi,
    the sample reported into documentation doesn't work ?
    https://www.ibm.com/support/knowledgecenter/en/SSLKT6_7.6.1.2/com.ibm.mbs.doc/autoscript/t_script_asychronous_job.html

    ------------------------------
    Diego Visentin
    EAM BU Director
    Tempestive S.p.A.
    Pordenone
    ------------------------------



  • 3.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Thu September 10, 2020 07:55 AM
    Edited by System Admin Wed March 22, 2023 11:54 AM


  • 4.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Thu September 10, 2020 09:26 AM
    It's not clear to me why you need a DBA to do a direct access to the MAXASYNCJOB table.
    The script in documentation should be used to define an autoscript that launch a second script named TESTASYNC in async way.


    ------------------------------
    Diego Visentin
    EAM BU Director
    Tempestive S.p.A.
    Pordenone
    ------------------------------



  • 5.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Thu September 10, 2020 09:32 AM
    Edited by System Admin Wed March 22, 2023 11:50 AM
    I keep getting a nullpointerexception on the execute method in my demo environments when I try to call it on either an attribute changing or object save. In none of the Maximo, SystemOut, or SystemErr logs does it cover what the nullpointerexception is related to so I'm a bit clueless. I've provided what I think is required based on the documentation below (in python, as we don't use the MBR scripting). Hopefully it works for you.

    Initial Script to create Job:
    asyncSet=service.getMboSet("ASYNCSCRIPT",mbo.getUserInfo())
    asyncMbo=asyncSet.setup()

    asyncMbo.setValue("AUTOSCRIPT","EMXTESTSCRIPT")
    asyncMbo.setValue("OBJECTNAME","WORKORDER")
    asyncMbo.setValue("WHERECLAUSE","workorderid="+str(mbo.getUniqueIDValue()))

    asyncSet.execute()


    Job Script:

    woSet=service.getMboSet("WORKORDER",userInfo)
    woSet.setWhere(where)
    woSet.reset()

    woMbo=woSet.moveFirst()
    if woMbo:
        woMbo.setValue("DESCRIPTION",woMbo.getString("DESCRIPTION")+ " IT WORKED!")
        woSet.save()
    woSet.close()

    *Edited to fix formatting of code. Apparently code snippet doesn't keep formatting*
    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 6.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Tue October 27, 2020 12:52 AM
    Edited by System Admin Wed March 22, 2023 11:44 AM




  • 7.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Fri November 13, 2020 09:57 AM
    Edited by System Admin Wed March 22, 2023 11:53 AM

    I looped back to this and learned a few important details. In the documentation there are some mistakes (either that or I misunderstand MBR scripting more than I thought I did). The first is in your script that you want to execute from an async job, the parameter is whereclause not where. So that script is like this:

    woSet=service.getMboSet("WORKORDER",userInfo)
    woSet.setWhere(whereclause)
    woSet.reset()

    woMbo=woSet.moveFirst()
    if woMbo:
        woMbo.setValue("DESCRIPTION",woMbo.getString("DESCRIPTION")+ " IT WORKED!")
        woSet.save()
    woSet.close()

    More importantly though, the AsyncJobSubmitter class that ScriptAsyncJobSubmitter extends requires that the non-persistent object has an owning object (it calls getOwner()) and that is where the nullpointerexception came in my example. I had to thus change it to something like this:

    asyncSet=mbo.getMboSet("$EMXASYNCSCRIPT","ASYNCSCRIPT","1=1")
    asyncMbo=asyncSet.setup()

    asyncMbo.setValue("AUTOSCRIPT","EMXTESTSCRIPT")
    asyncMbo.setValue("OBJECTNAME","WORKORDER")
    asyncMbo.setValue("WHERECLAUSE","workorderid="+str(mbo.getUniqueIDValue()))

    asyncSet.execute()

    Once I got to that I got an error because the async script that gets executed (in my example, EMXTESTSCRIPT) needs to be added to the ASYNCJOBNAME domain as that is what is referenced as the job name.

    EDIT: Figured out the looping issue and it was on my end.


    ------------------------------
    Steven Shull
    Director of Development
    Projetech Inc
    Cincinnati OH
    ------------------------------



  • 8.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Tue November 17, 2020 10:47 PM
    Edited by System Admin Wed March 22, 2023 11:51 AM
    I wonder if you could test out a Jython script that uses the python sleep() function (in the Time library). Just as an example of something slow that would process in the background.


  • 9.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Wed November 18, 2020 03:03 AM

    Hi,
    in Jython scripts for WebSphere administration this code works, so I guess it works in Maximo too:

    import time
    ...
    time.sleep(250)


    ------------------------------
    Diego Visentin
    EAM BU Director
    Tempestive S.p.A.
    Pordenone
    ------------------------------



  • 10.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Tue October 26, 2021 08:10 AM

    A thought occurred to me:

    If asynchronous automation scripts end up being too much of a pain to implement, then I wonder if the following would work for scenarios where we're trying to populate a field:

    1. Create an asynchronous attribute formula.
    2. Call an automation script from the attribute formula.
    Hopefully the automation script would run asynchronously…after a record was edited.

    That might be useful in some specific scenarios?




  • 11.  RE: Working example of asynchronous automation script? (7.6.1.2)

    Posted Fri May 07, 2021 09:53 AM
    FYI - A related post here:

    Executing Asynchronous Job Using Maximo Automation Script