Finding an Object by Id

To find an object by id, follow these steps:

  1. Use the newView() function to obtain the view object for programmatic access for the business object in question

  2. Call findByKey(), passing in a key object that you construct using the key() function

The new object will be saved the next time you save your work as part of the current transaction. The following example shows how the steps fit together in practice.

// Access the view object for the custom TroubleTicket object
def vo = newView('TroubleTicket_c')
def foundRows = vo.findByKey(key(100000000272002),1)
def found = foundRows.size() == 1 ? foundRows[0] : null;
if (found != null) {
  // Do something here with the found row
}

To simplify the code involved in this common operation, you could consider defining the following findRowByKey() global helper function:

  • Function Name: findRowByKey

  • Return Type: oracle.jbo.Row

  • Parameters: vo oracle.jbo.ViewObject, idValue Object

Function Definition

adf.util.logStart('findRowByKey')
def found = vo.findByKey(key(idValue),1)
return found.size() == 1 ? found[0] : null;

After defining this helper function, the example below shows the simplified code for finding a row by key.

// Access the view object for the custom TroubleTicket object
def vo = newView('TroubleTicket_c')
def found = adf.util.findRowByKey(vo,100000000272002)
if (found != null) {
  // Do something here with the found row
}