Sunday, 27 October 2024

Custom Line Number Functionality using Automation Script | IBM Maximo

We have a custom Object, LE_WPP, which has multiple lines and a foreign key from its parent Object, LE_WPPAYMENTID. We also have an attribute called Linenum.

We will execute the attribute launch point when the foreign key (LE_WPPAYMENTID) inserts by default, when we click on the new row button.


Launch Point Type: Attribute

Object: LE_WPP

Attribute: LE_WPPAYMENTID (Foreign Key)

Script:

vWPPAYMENTID=mbo.getString('LE_WPPAYMENTID')

vWPP=mbo.getThisMboSet()

vWPP.setWhere("LE_WPPAYMENTID = "+ vWPPAYMENTID+"") 

vWPP.setOrderBy("LE_PROGRESSID , LINENUM ");

#vcount=vWPP.count()

maxLineNum  = 0

vWPP1=vWPP.moveFirst()

Sunday, 11 August 2024

Run SQL directly from Automation script - Calling a Script Using Rest API

1.create a Script RUNSQL with below code

2. all this script with the sql in the end for instance:

https://[MAXIMO_URL]/maximo/oslc/script/runsql?method=SELECT&sql=SELECT assetnum,description,status FROM asset WHERE status='OPERATING' limit 5



from psdi.server.MXServer import getMXServer as MXS

def getHeader(rs):

    headerStr = ""    

    for i in range(rs.getMetaData().getColumnCount()):

        headerStr = headerStr + rs.getMetaData().getColumnName(i+1) + ","

    headerStr = headerStr[:-1] + "\r\n"                     # Remove the last "," and add a line break

    return headerStr


def getData(rs):

    dataStr = ""

    while (rs.next()):                                      #Loop through rows

        for i in range(rs.getMetaData().getColumnCount()):  #Loop through columns

            dataStr = dataStr + (rs.getString(i+1) or 'null') + ","

        dataStr = dataStr[:-1] + "\r\n"                     # Remove the last "," and add a line break

    return dataStr


### MAIN ###

connKey = MXS().getSystemUserInfo().getConnectionKey()

conn = MXS().getDBManager().getConnection(connKey)

method = request.getQueryParam("method").upper()            # SELECT or UPDATE,DELETE,INSERT

sql = request.getQueryParam("sql").upper()

stmt = conn.createStatement()


try:

    if method != 'SELECT':

        stmt.execute(sql)

        responseBody = "Done"

    else:

        rs = stmt.executeQuery(sql)

        headerStr = getHeader(rs)

        dataStr = getData(rs)

        responseBody = headerStr + dataStr

        rs.close()

finally:

    stmt.close()

    conn.commit()

    MXS().getDBManager().freeConnection(connKey)

#    https://[MAXIMO_URL]/maximo/oslc/script/runsql?method=SELECT&sql=SELECT assetnum,description,status FROM asset WHERE status='OPERATING' limit 5

######


maximo-runsql-automation/runsql.py at main · abdulqadeerel/maximo-runsql-automation

Thursday, 8 August 2024

Asset Deletion Query Sql | IBM Maximo

To delete asset totally from system including all related tables in Maximo System.

Single Asset Delete Query Example:

delete from AMCREWTOOL where ASSETNUM='WAP-0071';
delete from AMCREWWOTL  where ASSETNUM='WAP-0071';
delete from AREASAFFECTED where AFFECTEDASSETNUM='WAP-0071';
delete from ASSET  where ANCESTOR='WAP-0071';
delete from ASSET  where ASSETNUM='WAP-0071';
delete from ASSET  where PARENT='WAP-0071';
delete from ASSET where PLUSTALIAS='WAP-0071';
delete from ASSETANCESTOR  where ANCESTOR='WAP-0071';
delete from ASSETANCESTOR  where ASSETNUM='WAP-0071';
delete from ASSETAUDIT  where ASSETNUM='WAP-0071';
delete from ASSETCALIBRATION  where ASSETNUM='WAP-0071';
delete from ASSETFEASPECHIST  where ASSETNUM='WAP-0071';
delete from ASSETFEATURE  where ASSETNUM='WAP-0071';
delete from ASSETFEATUREHIST  where ASSETNUM='WAP-0071';
delete from ASSETFEATURESPEC  where ASSETNUM='WAP-0071';
delete from ASSETHIERARCHY  where ASSETNUM='WAP-0071';
delete from ASSETHIERARCHY  where PARENT='WAP-0071';
delete from ASSETHISTORY  where ASSETNUM='WAP-0071';
delete from ASSETLOCCOMM  where ASSETNUM='WAP-0071';
delete from ASSETLOCRELATION  where SOURCEASSETNUM='WAP-0071';
delete from ASSETLOCRELATION  where TARGETASSETNUM='WAP-0071';
delete from ASSETLOCRELHIST  where SOURCEASSETNUM='WAP-0071';
delete from ASSETLOCRELHIST  where TARGETASSETNUM='WAP-0071';
delete from ASSETLOCUSERCUST  where ASSETNUM='WAP-0071';
delete from ASSETMETER  where ASSETNUM='WAP-0071';
delete from ASSETMNTSKD  where ASSETNUM='WAP-0071';
delete from ASSETOPSKD  where ASSETNUM='WAP-0071';
delete from ASSETSPEC  where ASSETNUM='WAP-0071';
delete from ASSETSPECHIST  where ASSETNUM='WAP-0071';
delete from ASSETSTATUS  where ASSETNUM='WAP-0071';
delete from ASSETTOPOCACHE  where SOURCEASSETNUM='WAP-0071';
delete from ASSETTOPOCACHE  where TARGETASSETNUM='WAP-0071';
delete from ASSETTRANS  where ASSETNUM='WAP-0071';
delete from ASSETTRANS  where FROMPARENT='WAP-0071';
delete from ASSETTRANS  where TOPARENT='WAP-0071';
delete from ASSETWORKZONE  where ASSETNUM='WAP-0071';
delete from AUTOATTRUPDATE where ASSET='WAP-0071';
delete from CI  where ASSETNUM='WAP-0071';
delete from COLLECTDETAILS  where ASSETNUM='WAP-0071';

Thursday, 30 May 2024

Send Email from Automation Script, Multiple ways | Maximo

 1. Here’s a simple, famous 3-line code snippet to send an email. This example uses a communication template, but the body (MESSAGE) can be dynamically modified as needed

    ctMboSet = mbo.getMboSet("$commtemp","COMMTEMPLATE"," TEMPLATEID ='COE_SCHEDULED' ");

    ctMboSet.setQbeExactMatch("true")      

    ctMboSet.reset()

    ctMbo = ctMboSet.getMbo(0)

    ctMbo.setValue("MESSAGE", txtres)

    if(ctMbo is not None):

        ctMbo.sendMessage(mbo,mbo);