When a customization genuinely needs the next value from a Maximo-managed sequence, use Maximo's key-generation code rather than selecting or updating MAXSEQUENCE yourself. That keeps the logic consistent across DB2, Oracle and SQL Server and respects values reserved by Maximo's sequence cache.
Most scripts do not need to request a key explicitly. When you add an MBO whose unique column has a correctly configured sequence, Maximo normally assigns the value for you. Use this technique only when you need a sequence value independently of creating that record.
Generate a key
This Jython example obtains the next WORKORDER.WORKORDERID value:
from psdi.mbo import MaxSequence
#Get the database connection
connectionKey = mbo.getUserInfo().getConnectionKey()
dbConnection = None
try:
dbConnection = mbo.getMboServer().getDBConnection(connectionKey)
#Get the next value for the Work Order ID Sequence
nextSeqValue = MaxSequence.generateKey(
dbConnection,
"WORKORDER",
"WORKORDERID"
)
finally:
if dbConnection is not None:
mbo.getMboServer().freeDBConnection(connectionKey)The table and column names identify the row in MAXSEQUENCE; they are not arbitrary labels. Confirm that the pair is registered before using it. Add a Maximo sequence to an existing table explains the legacy metadata involved when an existing object has no sequence.
The example demonstrates the result by writing it into the current record's description:
#Set Description to next value to ensure we are retrieving a value
mbo.setValue("DESCRIPTION", str(nextSeqValue))That line is useful only in a disposable test record. In real code, pass nextSeqValue to the field or operation that actually needs the identifier. Do not overwrite business data merely to prove that the call worked.
Why this is safer than direct SQL
MaxSequence.generateKey follows Maximo's database-specific sequence implementation. That matters because the implementation is not identical on every database platform, and Maximo can reserve and cache ranges of values. Reading MAXRESERVED or calculating MAX(...) + 1 yourself can collide with another JVM, script or transaction.
The method returns a unique sequence value; it does not promise gap-free numbering. Calling it consumes a value even if the rest of the script fails or the business record is never saved. Do not use a Maximo sequence when regulations or business rules require an unbroken document number.
Connection and API cautions
Always release a connection obtained from the Maximo connection pool in a finally block. An exception between acquisition and release must not leave the connection checked out. Do not close the pooled JDBC connection directly; return it through the matching Maximo server method.
psdi.mbo.MaxSequence is an internal Java API rather than a stable automation-script service. Its available methods and connection lifecycle can differ between product releases. Validate the signature and the matching getDBConnection and freeDBConnection behavior against the Java documentation shipped with the exact Maximo version you run.
Test the script in a non-production environment, preferably with a dedicated custom sequence rather than WORKORDERID. Run concurrent tests if more than one JVM or cron task can execute it, and confirm that the resulting values remain unique without exhausting the database connection pool.