Maximo Open Forum

 View Only
  • 1.  Automation script

    Posted 06-01-2023 03:47

    Hi,

    Can anyone help me to know how to write ( where changedate > CAST(GETDATE() AS Date )(which is in sql) in automation script?

    I tried:

    userInfo= MXServer.getMXServer().getSystemUserInfo()

    cal= calendar.getInstance ()

    datetime=cal.getTime()

    currentSet= MXServer.getMXServer().getMboSet("PR",userInfo)

    currentSet.setWhere(

               "changedate > datetime"

    )

    But getting error that" invalid column name datetime"

    Please help


    #Administration
    #Analytics
    #Architecture
    #Assets
    #CivilInfrastructure
    #Customizations
    #EndUser
    #EverythingMaximo
    #HSE/OilandGas
    #Infrastructure
    #Integrations
    #Inventory
    #IoT
    #LifeScience/Calibration
    #Linear
    #MaximoApplicationSuite
    #MaximoForAviation
    #MaximoUserGroups
    #Mobility
    #Nuclear
    #Procurement
    #Reporting
    #Scheduling
    #Security
    #ServiceProvider
    #Spatial
    #Transportation
    #Utilities
    #WorkCenters
    #WorkManagement

    ------------------------------
    Deepa P
    ------------------------------


  • 2.  RE: Automation script

    Posted 06-02-2023 00:53

    Hi Deepa,

    Try the below code and check whether this works. You may need to import some packages.

    from psdi.util import MXFormat
    from psdi.server import MXServer
    from java.util import Date
    from psdi.mbo import SqlFormat
    #datetime= MXServer.getMXServer().getDate()
    #datetime = MXFormat.getDateOnly(datetime) 

    cal= calendar.getInstance ()

    datetime=cal.getTime()

    currentSet= MXServer.getMXServer().getMboSet("PR",userInfo)

    SqlFormat sqf = new SqlFormat(mbo.getUserInfo(), "changedate > :1");
    sqf.setDate(1, datetime);
    currentSet.setWhere(sqf.format())
    currentSet.reset()



    ------------------------------
    Subhransu Sekhar Sahoo
    Tata Consultancy Services
    ------------------------------



  • 3.  RE: Automation script

    Posted 06-02-2023 06:10
    Edited by Deepa P 06-02-2023 06:19

    Hi Subhransu,

    Thank you so much. It worked. I would request you to help me with another thing I am stuck with. For getting data from one table we use:

    currentset=mxserver.getMboSet("PR",userInfo)

    If in sql there are 2 tables: select * from pr,prlines where pr.prnum=prline.prnum and pr.siteid =prline.siteid.

    How do I get two tables in the automation script  or rather put the above sql query in the script?



    ------------------------------
    Deepa P
    ------------------------------



  • 4.  RE: Automation script

    Posted 06-02-2023 10:39

    The "Master-Detail" pattern is thoroughly baked into Maximo. As such, queries with two tables in the FROM clause are exceedingly rare.

    In keeping with the Master-Detail pattern, you would achieve your end as shown below. Note that I leave out imports and error checking so you can focus on the pattern: Get PR (the Master) then navigate from there to PRLINE (the Detail) via a Relationship Note that Maximo will substitute values from the Master in place of the :references in getMboSet()'s whereClause argument.

    prSet = mxserver.getMboSet("PR", userInfo)
    prSet.setWhere("changedate > getdate()")
    prSet.reset()
    pr = prSet.moveFirst()
    prLineSet = pr.getMboSet("$tempPrLineRelationship", "PRLINE", "prnum = :prnum and siteid = :siteid")
    prLine = prLineSet.moveFirst()
    print(prLine.getString("DESCRIPTION"))
    # we got prSet from MXServer; it's our job to close it to avoid leaks
    prSet.close()


    ------------------------------
    Jason Uppenborn
    Cohesive
    ------------------------------



  • 5.  RE: Automation script

    Posted 06-05-2023 11:51

    As Jason says it is important to use the relationships that are already defined in Maximo.

    These are defined in the Relationship tab for a specific MBO e.g. PR.

    These relationships are what Maximo uses for the vast majority of its queries and the IBM out of the box relationships will be modified if IBM make significant changes to the data model.

    If you know the name of the relationship then you can use the getMboSet method to use the relationship without having to know the SQL that the relationship is using.



    ------------------------------
    mark robbins
    Cohesive
    IBM Champion 2017-2023 Inclusive
    See my blog on Maximo support related topics here:
    https://www.linkedin.com/pulse/maximo-support-advice-from-non-ibm-engineer-article-mark-robbins/
    ------------------------------



  • 6.  RE: Automation script

    Posted 06-02-2023 10:51

    Hi Deepa,

    You can directly pass this kind of sql self join statements into a SQLFormat Object. 



    ------------------------------
    Subhransu Sekhar Sahoo
    Tata Consultancy Services
    ------------------------------