Maximo

 View Only
Expand all | Collapse all

Pass Report Parameters through automation script

  • 1.  Pass Report Parameters through automation script

    Posted Fri July 26, 2024 12:40 AM

    Hello,

    We have a custom report that does not have any report parameters and this report would be launched on click of a button  based on the records selected by the user. For example if there are 3 records displayed and user selects the second record then the report should run only for the second record. This selection is based on a non-persistent check box. I'm not sure on how we can pass the MBO to the report during run time.  At the moment the report is getting executed for all the 3 records. 

    I have simply tried to fetch the report from REPORT mbo and invoke loadDialog using action launch point. 



    ------------------------------
    MAX092012
    ------------------------------


  • 2.  RE: Pass Report Parameters through automation script

    Posted Mon July 29, 2024 03:08 PM
    Edited by Bradley Downing Mon July 29, 2024 03:33 PM

    HI!

    There are a few ways to launch a report for a given record.  You can go into the report application and check the box to register the report to run from the Main page toolbar. This will pass only the current record into the "where clause".  No need for an automation script.  If you have the report also registered to run from the list page then it will pass all the records listed on the List page (Browser List checkbox enabled) Are you trying to click on the checkbox on the left side to create a subset of listed records and then run report for selected sub records?

    Quick update:  I just checked this ability for the WOTRACK.RPTDESIGN in MAS 8.11 (Manage 8.7.9) and if in Maxdemo db you filter work orders on Asset like '1143%' then you will get twenty seven work orders. Then scroll to bottom and click on "Select Records". Then pick your desired records (let's say three.).  Then click on Report List Icon. You will get three records.  Is this what you are trying to accomplish?

    ------------------------------
    Bradley K. Downing , MBA
    Senior Solution Architect
    IBM
    Bakersfield
    ------------------------------



  • 3.  RE: Pass Report Parameters through automation script

    Posted Mon July 29, 2024 11:40 PM

    Hi Bradley,

    Thank you for your response!  The report would be triggered from a sub tab, for example in work order tracking application > actual tab > in the labor sub tab there are 5 labors and we would select 3 labors and click on a button to launch a custom report that would run only for these 3 selected labors . I'm able to run the report by invoking the loadDialog(pageNum) however I'm unable to pass the 3 labors selected, instead the report is running for all the 5 labors. Please note that I'm able to retrieve the 3 labors that are selected however I'm unable to pass them to the report. I'm not sure if there is a way to pass the where clause while invoking the loadDialog. 



    ------------------------------
    MAX092012
    ------------------------------



  • 4.  RE: Pass Report Parameters through automation script

    Posted Tue July 30, 2024 02:30 PM

    Ah!  OK use case is clearer now.  My view is that if you have the MBO you should be able to grab the record selection from that.  Dunno what that might actually be though (w/r/t the element within the MBO.) Also if it is non persistent then that will pose an additional challenge. That is beyond my knowledge. @Steven Shull might know that.  But theoretically if you can grab the recrod selection then you can "re-build" the "where" param that is passed to the report.



    ------------------------------
    Bradley K. Downing , MBA
    Senior Solution Architect
    IBM
    Bakersfield
    ------------------------------



  • 5.  RE: Pass Report Parameters through automation script

    Posted Tue July 30, 2024 04:33 PM

    Hi Bradley,

    As mentioned earlier, I'm able to grab the records selected however the only challenge that I'm facing here is to rebuild the where clause and pass it to the report engine. I need to pass the where clause to the birt report viewer which seems to be a challenge as we can do that for direct print or scheduling a report.  Below is the script that I'm calling on click of the button and here I'm not sure how to pass the where clause as report parameter,

    session=service.webclientsession()
    appName=session.getCurrentApp().getApp()
    where ="REPORTNAME ='customrpt.rptdesign' and APPNAME='"+appName.upper()+"' "
    reportSet = mbo.getMboSet("$REPORTSPI","REPORT",where) 
    reportSet.reset() 

    report = reportSet.moveFirst()
     if report is not None:
               reportnum = str(report.getInt("REPORTNUM"))
                pageName = "reportd"+reportnum 
                session.loadDialog(pageName)



    ------------------------------
    MAX092012
    ------------------------------



  • 6.  RE: Pass Report Parameters through automation script

    Posted Wed July 31, 2024 10:42 AM
    Edited by Matt F Wed July 31, 2024 10:58 AM

    Jason has done similar in an example here, which I believe should fulfill your request?

    Or, Alex has also done similar here.

    I've yet to test this myself but now I'm intrigued. Let me know how it goes!

    ------------------------------
    Matt F
    ------------------------------



  • 7.  RE: Pass Report Parameters through automation script

    Posted Wed July 31, 2024 02:34 PM
    Edited by Matt F Wed July 31, 2024 03:12 PM

    I was able to get this working using the script below with the WO Details report. On the List screen, I had filtered on 3 WO's and received a print out of each one as expected. 

    from psdi.mbo import MboConstants
    from psdi.server import MXServer
    from com.ibm.tivoli.maximo.report.birt.runtime import ReportParameterData
    
    # Get the current session, app, and whereclause
    session = service.webclientsession()
    appName = session.getCurrentApp().getApp()
    currentWhereClause = mbo.getThisMboSet().getUserWhere()
    
    # Get the report and parameter
    reportMboSet = mbo.getMboSet("$REPORTSPI", "REPORT", "REPORTNAME ='woprint.rptdesign' and APPNAME='" + appName.upper() + "'")
    reportMboSet.reset()
    
    report = reportMboSet.moveFirst()
    if report is not None:
        reportnum = str(report.getInt("REPORTNUM"))
        pageName = "reportd" + reportnum
        parameterData = ReportParameterData()
        parameterData.addParameter("where", currentWhereClause)
        session.loadDialog(pageName)
        
        
        

    @Jason VenHuizen - any improvements or best practices that you'd recommend to the above? My other thought would be if there's no need to engage with the Request Page dialog, they could utilize the service.invokeMethod and just run the report immediately? But i guess that depends on the use case if there's ever a need to e-mail/schedule it, then using the above should suffice.

    Cheers,

    ------------------------------
    Matt F
    ------------------------------



  • 8.  RE: Pass Report Parameters through automation script

    IBM Champion
    Posted Wed July 31, 2024 03:12 PM

    My only comment is a preference to the the psdi.mbo.SqlFormat class for creating where clauses.

    https://www.sharptree.io/blog/2022/2022-01-31-sql-format/

    from psdi.mbo import MboConstants, SqlFormat
    from psdi.server import MXServer
    from com.ibm.tivoli.maximo.report.birt.runtime import ReportParameterData
    # Get the current session, app, and whereclause
    
    session = service.webclientsession()
    appName = session.getCurrentApp().getApp()
    currentWhereClause = mbo.getThisMboSet().getUserWhere()
    # Fetch the report MBO
    sqlf = SqlFormat("reportname = :1 and appname = :2")
    sqlf.setObject("REPORT", "REPORTNAME", "woprint.rptdesign")
    sqlf.setObject("REPORT", "APPNAME", appName.upper())
    
    reportMboSet = mbo.getMboSet("$REPORTSPI", "REPORT", sqlf.format())
    reportMboSet.reset()
    report = reportMboSet.moveFirst()
    if report is not None:    
        reportnum = str(report.getInt("REPORTNUM"))    
        pageName = "reportd" + reportnum    
        session.loadDialog(pageName)        
        # Create the report parameter data    
        parameterData = ReportParameterData()    
        parameterData.addParameter("where", currentWhereClause)


    ------------------------------
    Jason VenHuizen
    https://sharptree.io
    https://opqo.io
    ------------------------------



  • 9.  RE: Pass Report Parameters through automation script

    Posted Wed July 31, 2024 09:37 PM

    Thanks, Jason! I read through your blog and with a few adjustments, I was able to get the script running using the SqlFormat class. Thanks for the tip!

    from psdi.mbo import MboConstants, SqlFormat
    from psdi.server import MXServer
    from com.ibm.tivoli.maximo.report.birt.runtime import ReportParameterData
    
    # Get the current session, app, and whereclause
    session = service.webclientsession()
    appName = session.getCurrentApp().getApp()
    currentWhereClause = mbo.getThisMboSet().getUserWhere()
    
    # Fetch the report MBO
    sqlf = SqlFormat(mbo, "reportname = :1 and appname = :2")
    sqlf.setObject(1, "REPORT", "REPORTNAME", "woprint.rptdesign")
    sqlf.setObject(2, "REPORT", "APPNAME", appName.upper())
    
    reportMboSet = mbo.getMboSet("$REPORTSPI", "REPORT", sqlf.format())
    reportMboSet.reset()
    report = reportMboSet.moveFirst()
    if report is not None:    
        reportnum = str(report.getInt("REPORTNUM"))    
        pageName = "reportd" + reportnum    
        # Create the report parameter data    
        parameterData = ReportParameterData()    
        parameterData.addParameter("where", currentWhereClause)
        #Load request page
        session.loadDialog(pageName)


    ------------------------------
    Matt F
    ------------------------------



  • 10.  RE: Pass Report Parameters through automation script

    Posted Tue August 06, 2024 08:32 PM

    Thank you Matt and Jason. Your solution works in case of list tab however my requirement in the sub tab of a particular application where in the getUserWhere() does not return the expected records selected. Hence I used a temporary table to store the records that are selected and then passed the where clause to the report. 



    ------------------------------
    MAX092012
    ------------------------------



  • 11.  RE: Pass Report Parameters through automation script

    IBM Champion
    Posted Tue August 06, 2024 08:35 PM

    Assuming it is some sub-table in the application you can use the application context to get a reference to the table bean and then get the where clause for that bean to pass along to the report.  I don't have an example readily available, but if you want more details let me know and I can create an example for you.

     

    Regards,

    Jason






  • 12.  RE: Pass Report Parameters through automation script

    Posted Wed July 31, 2024 07:45 PM

    Based on what @Matt F and @Jason VenHuizen have provided I believe they have provided you with the code needed. When I saw your response I was going to start down a long winded explanation that you need to grab the mboSet where and then do all sorts of stuff that the code does.  So, I am very glad I need not bloviate with words! Ha! ;) Well Done gents!!



    ------------------------------
    Bradley K. Downing , MBA
    Senior Solution Architect
    IBM
    Bakersfield
    ------------------------------