Monday, June 29, 2015

Unexpected MboSet Reset

I spent about a half day on this one.

We have a customization where the MEASUREMENT table contains a TICKETID column pointing to a record in the TICKET table.

There is a relationship called TICKETS with these properties:
PARENT: MEASUREMENT
CHILD: TICKET
WHERECLAUSE: ticketid = :ticketid


 MboRemoteSet measurements = /* an mboset of measurements. */  
   
 MboRemote measurement = /* a measurement record being updated */  
 MboSetRemote tickets = measurement.getMboSet("TICKETS");  
 MboRemote ticket = tickets.add();  
 measurement.setValue("TICKETID", ticket.getString("TICKETID"));  
   
 /* in a later block of code, but in the same transaction */  
 MboSetRemote tickets = measurement.getMboSet("TICKETS");  
 MboRemote ticket = tickets.getMbo(0);  
 /* ticket is now null! */  

The problem was a reset() on the second getMboSet("TICKETS").

The first getMboSet("TICKETS") created a related MboSet to the TICKETS table.  Internally, Maximo stores the relationship where clause used to create that relationship.  In the first case, that relationship is "ticketid = ''".

In the second getMboSet("TICKETS") the relationship where clause has become "ticketid = 'new ticketid'".  Maximo sees this difference and resets the MboSet before returning it to the caller.

I ended up with a MEASUREMENT record referencing a TICKET that didn't exist in the database. 


The fix was to reset the relationship after setting TICKETID.

 measurement.setValue("TICKETID", ticket.getString("TICKETID"));  
   
 RelationInfo ri = measurements.getMboSetInfo().getRelationInfo(tickets.getRelationName()); 
 SqlFormat sf = new SqlFormat(measurement, ri.getSqlExpr()); 
 tickets.setRelationship(sf.format());  

This reset the relationship where clause between MEASUREMENT and TICKETS without resetting the MboSet and losing my new TICKET object.

No comments:

Post a Comment