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.
Original Message:
Sent: 06-02-2023 10:38
From: Jason Uppenborn
Subject: Automation script
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 leaksprSet.close()
------------------------------
Jason Uppenborn
Cohesive
Original Message:
Sent: 06-02-2023 06:10
From: Deepa P
Subject: Automation script
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
Original Message:
Sent: 06-02-2023 00:53
From: Subhransu Sekhar Sahoo
Subject: Automation script
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())
------------------------------
Subhransu Sekhar Sahoo
Tata Consultancy Services
Original Message:
Sent: 06-01-2023 03:46
From: Deepa P
Subject: Automation script
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
------------------------------