Maximo

Maximo-ICON.png

Maximo

Learn how to increase the operational efficiency of the assets you manage, and improve overall equipment effectiveness by using IoT data and AI.

Maximo-ICON.png

TRIRIGA

Reduce the operational costs of the facilities you manage, and create more engaging occupant experiences through the application of IoT data and AI.

Maximo-ICON.png

Engineering

Learn how IoT data and AI are being applied to transform the end-to-end engineering lifecycle.

Expand all | Collapse all

List View script only works for the first 22 records in resultset

  • 1.  List View script only works for the first 22 records in resultset

    Posted Thu September 10, 2020 04:04 PM
    Edited by User1971 Thu September 10, 2020 04:41 PM

    Maximo 7.6.1.2:

    I have an automation script that I use to make mass updates to a specific field in the List View records.

    Unfortunately, the updates are only being applied to the first 22 records in the resultset.

    Does anyone know why it only works on the first 22 records?

    Thanks.

    --------------------------------------------------------------------------------------


    from psdi.common.context import UIContext
    from psdi.webclient.system.session import WebClientSessionManager
    from psdi.webclient.system.controller import SessionContext, Utility, WebClientEvent
    from java.lang.System import out

    assetSet=service.webclientsession().getCurrentApp().getResultsBean().getMboSet()
    attrName=mbo.getString("C_ATTRNAME")
    value = mbo.getString("C_VAL")

    for i in range(assetSet.getSize()):
        mbo = assetSet.getMbo(i)
        if not mbo is None:
          mbo.setValue(attrName,value,11L)

    c = UIContext.getCurrentContext().getWebClientSession()
    Utility().sendEvent(WebClientEvent("dialogok", c.getCurrentPageId(), None, SessionContext(c)))
    assetSet.save()







  • 2.  RE: List View script only works for the first 22 records in resultset

    Posted Fri September 11, 2020 10:05 AM
    Edited by Jason Uppenborn Fri September 11, 2020 04:44 PM
    Based on the API docs, MboSet.getSize() returns "the current size of the collection" while MboSet.count() returns "The sum of the count from the database (COUNT_DATABASE) plus newly added Mbos that have not yet been saved (COUNT_ADDITIONS)." So, you are probably working with what has been loaded into the set instead of how big the set is.

    That said, I wouldn't use getSize() or count(). Instead, I would tend to write your code this way.

    i = 0
    asset = assetSet.getMbo(i)
    while asset:
        # do your stuff
        ​i += 1
        asset = assetSet.getMbo(i)

    Update: Made it more clear that I don't advocate using getSize() or count().
    ------------------------------
    Blessings,
    Jason Uppenborn
    Sr. Technical Maximo Consultant
    Ontracks Consulting
    ------------------------------



  • 3.  RE: List View script only works for the first 22 records in resultset

    Posted Fri September 11, 2020 10:21 AM

    Agreed with Jason that your issue is probably with getSize() (that's burned me in the past). But when you don't need to know how many records, don't use getSize() or count(). Count is executing an additional database query and as you've found, getSize() isn't reliable. Just loop until you get to the end of the set. Just use this:

    assetMbo=assetSet.moveFirst()
    while assetMbo:
        assetMbo.setValue(attrName,value,11L)
        assetMbo=assetSet.moveNext()

    I'd also be really cautious about 11L. You're suppressing validation and action with that which means that you can get bad values. If you are just trying to make it editable when it's read-only, use 2L instead (or import MboConstants and use MboConstants.NOACCESSCHECK).



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



  • 4.  RE: List View script only works for the first 22 records in resultset

    Posted Fri September 11, 2020 10:37 AM
    Since moveXxxx() changes the "current record" pointer, and we are talking about the user-facing MboSet in the List tab, I would prefer using getMbo(). Also, Mbo implements MboConstants, so you should be able to use mbo.NOACCESSCHECK, saving an import but still achieving more readable code.

    ------------------------------
    Blessings,
    Jason Uppenborn
    Sr. Technical Maximo Consultant
    Ontracks Consulting
    ------------------------------



  • 5.  RE: List View script only works for the first 22 records in resultset

    Posted Fri September 11, 2020 11:57 AM
    Good feedback, especially on the implements. I don't think I've ever seen it used that way and I love avoiding an import (especially since I use this in a lot of scripts).

    I also missed in your example that you weren't actually using count (you were just discussing the difference above) so I apologize for that. I read the top part and assumed that was in the solution. Your way avoids the performance impact and keeps the position of the set intact which makes sense on the list tab.

    A lot of examples I see online use the count to determine how many records to iterate which can slow down the process, especially if the query takes a while to execute. In one time cases like this it probably isn't that big of a deal, but we dealt with a case where Anywhere lookup data was increased significantly because each assetspec was executing a count against assetattribute in addition to the query to get asset attribute. When you're pulling 500,000 specs even a 2 ms query per count will have a serious impact to performance.

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