Hi Steven,
at first, many thanks for writing that down and publishing!
This may be a bit offtopic from the question, but related to your answer.
You write
Starting from 7612, the following function will be added in the "service" variable that will allow you to check it easily:
if service.isLoggingEnabled():
service.log("count of mbos "+mboset.count())
I am currently looking at the ScriptService of TPAE7612 (IFIX026) and don't see that "isLoggingEnabled" function. Are you sure it is in it?
You also write:
You may want to do costly Object init scripts only when the object is initialized from the Main tab (UI) and not from the List tab. This is because in such cases, the following sample code bis helpful:
from psdi.common.context import UIContext
if UIContext.getCurrentContext() is not None and UIContext.isFromListTab()==False:
..costly initlization..
(Btw, there is an error in it, it should be "UIContext.getCurrentContext().isFromListTab()")
Since there is service.webclientsession(), i do it this way so i don't need to import UIContext:
if service.webclientsession() and service.webclientsession().getCurrentApp().onListTab():
... costly initialization...
Are there differences? What is the better way?
Belonging to that, is there any way to stop processing if we are in a resultset in startcenter? I neither get a UIContext nor a WebClientSession.
------------------------------
Andreas Brieke
IT Service Management Consultant
SVA System Vertrieb Alexander GmbH
------------------------------
Original Message:
Sent: Mon November 14, 2022 09:59 AM
From: Steven Shull
Subject: Automation Scripts: Do/Don't, Performance & Code Styling.
Truthfully, it's a bit light but https://ibm-maximo-dev.github.io/maximo-autoscript-documentation/bestpractice/overview is where we intend to cover this.
I want to enhance this when I have time and create a series of blogs to go a bit deeper. For example, choosing the right launch point is critical but we only talk about a few examples of it here and there are a lot of examples of code that works but isn't optimized because the developer chose the wrong event.
I'd also inform developers to avoid count() entirely over just minimizing it. There are very few circumstances where you need to know the actual count but don't need to process the data. Typically, I see developers using this to loop through records or determine if records exist. Both can be achieved without using count() which will always cause another database query. For example, if you want to determine if a record exists use set.notExist() instead. This will check the in-memory set first to see if we have any Mbos. If the set hasn't been initialized it will execute a query against dummy_table with an exist() statement instead. This allows the database to stop processing once 1 record is returned whereas the count requires every record to be returned from the query first. If you're trying to loop through records, start at 0 and iterate until your Mbo is null.
------------------------------
Steven Shull
Original Message:
Sent: Fri November 11, 2022 11:13 AM
From: Dianne Woodley
Subject: Automation Scripts: Do/Don't, Performance & Code Styling.
Hi All,
Is there any documentation that consolidate all automation scripts coding recommendation (avoid performance degradation, avoid memory leaks, usability and supportability)?
Thanks!
------------------------------
Dianne Woodley
------------------------------
#MaximoIntegrationandScripting
#Maximo
#AssetandFacilitiesManagement