Collecting Errors

When multiple business functions are called, a potential exists for several errors and warnings to be returned by the business functions. You should gather all errors and warnings in the E1MessageList object for all of the business functions that are called so that all errors and warnings are sent to the caller.

When a business service calls a business function, the business function collects all style errors, defined as error messages in the JD Edwards EnterpriseOne data dictionary, in an ArrayList. The business function always returns an E1MessageList object to its caller. The E1MessageList object contains an ArrayList of the messages returned from a business function call. If no messages are returned, the ArrayList is empty. To determine the state of the E1MessageList object or to determine whether any errors have occurred, you can use one of these methods to call the E1MessageList:

  • hasErrors()

  • hasWarning()

  • hasInfoMessages()

The business service foundation provides several methods that let you add, remove, change, and append to the ArrayList messages.

This code sample shows how to use hasErrors() to call the E1MessageList:

                if (messages.hasErrors()) {
               //Get the string representation of all the messages.
               String error = messages.getMessagesAsString();
               //Throw new BusinessServiceException
               throw new BusinessServiceException(error, context);
           }  

This code sample shows adding a prefix to an E1MessageList to show where errors occurred in a business function:

private static E1MessageList callAddressBookMasterMBF(IContext context,
                                       IConnection connection,
                                       InternalValueObject internalVO,
                                       String programId){
   
   //create new bsfnParams object
   BSFNParameters bsfnParams = new BSFNParameters();
   //set values for bsfn params based on internal vo attribute values
   bsfnParams.setValue("mnAddressBookNumber", 
                       internalVO.getMnAddressBookNumber());
   bsfnParams.setValue("szLongAddressNumber", 
                       internalVO.getSzLongAddressNumber());
   bsfnParams.setValue("szTaxId", internalVO.getSzTaxId());
   ...
   //execute the AddressBookMasterMBF business function
   bsfnService.execute(context,connection, "AddressBookMasterMBF",bsfnParams);
   //set internal VO attributes based on values passed back from bsfn
internalVO.setMnAddressBookNumber((MathNumeric)bsfnParams.getValue
("mnAddressBookNumber"));
internalVO.setSzLongAddressNumber((String)bsfnParams.getValue
("szLongAddressNumber"));
   internalVO.setSzTaxId((String)bsfnParams.getValue("szTaxId").
toString());
   internalVO.setSzAlphaName((String)bsfnParams.getValue
("szAlphaName"));
   ...
bsfnParams.getE1MessageList().setMessagePrefix("AddressBookMasterMBF
(N0100041): ");
    //return any errors, warnings, or informational messages to the 
    //caller
   return bsfnParams.getE1MessageList();

This code sample shows calling the PhonesMBF within a loop and handling the errors that are being collected:

public static E1MessageList addPhones(IContext context, IConnection 
connection,
 InternalProcessPhone internalVO){
       E1MessageList retMessages = new E1MessageList();
       
       E1MessageList phonesMessages;
       //Add All phones passed in
       for (int i = 0; i < internalVO.getPhones().length; i++) {
           phonesMessages = callPhonesMBFtoAdd(context, connection, 
internalVO, i);
           //set message prefix to add line number
           phonesMessages.setMessagePrefix("Phone line no. sent in"+
(i+1));
           //collect messages for all phones.
           retMessages.addMessages(phonesMessages);
       }
      //send messages back to caller
      return retMessages;

This sample code shows returning the messages to the caller and adding them to the existing message object:

  public static E1MessageList addAddressBook(IContext context, 
IConnection connection,
  InternalAddAddressBook internalVO){
       E1MessageList retMessages = null;
       ...
            //if no errors in address book, continue and add phones.
       if (retMessages != null && !retMessages.hasErrors()) {
           E1MessageList phonesMessages;
      //RI:  Business service call to business service
           //call PhonesProcessor
           ...
           phonesMessages = PhonesProcessor.addPhones(context,
connection,phones);
           //If errors occur, change the error type to WARNING
           if (phonesMessages != null && phonesMessages.hasErrors()){
               phonesMessages.changeMessageType(E1Message.ERROR_MSG_
TYPE, 
E1Message.WARNING_MSG_TYPE);
           }
           if (retMessages == null)
           {
             retMessages = phonesMessages;
           }
           else
           {
             retMessages.addMessages(phonesMessages);
           }
       } 
       ....
       return retMessages;