Calling Business Functions

A business function is an encapsulated set of business rules and logic that can be reused by multiple applications. Business functions provide a common way to access the JD Edwards EnterpriseOne database. A business function performs a specific task.

You use the business service foundation Business Function Call Wizard to create a business function call.

See "Understanding Business Function Calls" in the JD Edwards EnterpriseOne Tools Business Services Development Guide.

This code sample is generated by the Business Function Wizard:

       //calls method which then executes BSFN AddressBookMBF
       //RI: This private function is created by the wizard, The 
       //business function will be executed inside this internal function
       messages = callAddressBookMasterMBF(context, internalVO,programId);

The wizard creates a generic method. You modify the signature of the method and complete the code for the objects that will be accessed for mapping to and from the business function call. The wizard creates InputVOType as a placeholder in the signature for the internal value object class name that you provide.

This code sample shows a business function call that was created by the wizard:

/**
  * Calls the AddressBookMasterMBF(N0100041) business function which has 
  * the D0100041 data structure.
  * @param context provides the connection for the business function call 
  * and logging information
  * @param TODO document input parameters
  * @return A list of messages if there were application errors, warnings,
  * or informational messages. Returns null if there were no messages.
  */
     private static E1MessageList callAddressBookMasterMBF(IContext 
context, IConnection connection, InputVOType internalVO) {
     BSFNParameters bsfnParams = new BSFNParameters();
     // map input parameters from input value object
     bsfnParams.setValue("cActionCode", internalVO.getCActionCode());
     bsfnParams.setValue("cUpdateMasterFile", internalVO.getCUpdateMaster
File());
     bsfnParams.setValue("cProcessEdits", internalVO.getCProcessEdits());
     bsfnParams.setValue("cSuppressErrorMessages", internalVO.getCSuppress
ErrorMessages());
     bsfnParams.setValue("szErrorMessageID", internalVO.getSzErrorMessage
ID());
     bsfnParams.setValue("mnSameAsExcept", internalVO.getMnSameAsExcept());
     bsfnParams.setValue("mnAddressBookNumber", internalVO.getMnAddressBook
Number());
     ...
       try {
          //get bsfnService from context
          IBSFNService bsfnService = context.getBSFNService();
          //execute business function
          bsfnService.execute(context, connection, "AddressBookMasterMBF", 
bsfnParams);
      } catch (BSFNServiceInvalidArgException invalidArgEx) {
         //Create error message for Invalid Argument exception and return 
         //it in ErrorList
          E1MessageList returnMessages = new E1MessageList();
          returnMessages.addMessage(new E1Message(context, "018FIS", 
invalidArg 
Ex.getMessage()));
          return returnMessages;
      } catch (BSFNServiceSystemException systemEx) {
          //Create error message for System exception and return it in 
          //ErrorList
          E1MessageList returnMessages = new E1MessageList();
          returnMessages.addMessage(new E1Message(context, "019FIS", 
systemEx.getMessage()));
          return returnMessages;
      }
     //map output parameters to output value object
     internalVO.setMnAddressBookNumber(bsfnParams.getValue("mnAddressBook
Number");
     internalVO.setSzLongAddressNumber(bsfnParams.getValue("szLongAddress
Number");
     internalVO.setSzTaxId(bsfnParams.getValue("szTaxId"));
     internalVO.setSzAlphaName(bsfnParams.getValue("szAlphaName"));
     internalVO.setSzSecondaryAlphaName(bsfnParams.getValue("szSecondary
AlphaName"));
     internalVO.setSzMailingName(bsfnParams.getValue("szMailingName"));
     internalVO.setSzSecondaryMailingName(bsfnParams.getValue("szSecondary
MailingName"));
     internalVO.setSzDescriptionCompressed(bsfnParams.getValue
("szDescriptionCompressed"));
     internalVO.setSzBusinessUnit(bsfnParams.getValue("szBusinessUnit"));
     internalVO.setSzAddressLine1(bsfnParams.getValue("szAddressLine1"));
     //return any errors, warnings, or informational messages to the caller
     return bsfnParams.getE1MessageList();
   }

After the wizard creates the code for the generic method, you modify the code as needed. You might need to:

  • Add parameters to be passed.

    At a minimum, the internal value object includes an IContext object and an IConnection object, generated by the wizard, and an internal value object, which you define. You may need to pass an additional parameter such as an internalProcessing value object for processing fields that should not be exposed.

  • Fix mappings if required.

    The generated code assumes that all fields can be mapped directly to and from the internal value object. If an additional structure exists in the internal value object or some fields should be mapped from class constant fields, you must fix the mapping statements where this assumption is not true. JDeveloper identifies incorrect statements.

  • Fix the data type of the object retrieved from bsfnParams.

    The generated code adds a cast argument when mapping to internalVO by getting values from the bsfnParams object. The bsfnParams object is a collection of objects and when an object is retrieved, the type needs to be cast to the correct data type so that it can be added to the internalVO reference, as illustrated in this code sample:

    private static E1MessageList callAddressBookMasterMBF(IContext context, 
                                             IConnection connection,
                                             InternalAddAddressBook internalVO, 
                                             String programId) {
           // create new bsfnParams object
           BSFNParameters bsfnParams = new BSFNParameters();
          //set values for bsfn params based on internal vo attribute values
           bsfnParams.setValue("cActionCode", ACTION_CODE_ADD);
           bsfnParams.setValue("cUpdateMasterFile", UPDATE_MASTER_TRUE);
           bsfnParams.setValue("cProcessEdits", PROCESS_EDITS_TRUE);
           bsfnParams.setValue("cSuppressErrorMessages", SUPPRESS_ERROR_FALSE);
           bsfnParams.setValue("szVersion", internalVO.getSzVersion());
           bsfnParams.setValue("mnAddressBookNumber", 
                               internalVO.getMnAddressBookNumber());
           bsfnParams.setValue("szLongAddressNumber", 
                               internalVO.getSzLongAddressNumber());
           bsfnParams.setValue("szTaxId", internalVO.getSzTaxId());
           bsfnParams.setValue("szSearchType", internalVO.getSzSearchType());
           ...
           bsfnParams.setValue("szState", internalVO.getSzState());
           bsfnParams.setValue("szCountry", 
                               internalVO.getSzCountry());
            //set program id to value retrieved in business service properties
            bsfnParams.setValue("szProgramId", programID );
           try {
                //get bsfnService from context
                IBSFNService bsfnService = context.getBSFNService();
                //execute business function
    
                bsfnService.execute(context, connection, "AddressBookMaster
    MBF", bsfnParams);
            } catch (BSFNServiceInvalidArgException invalidArgEx) {
               //Create error message for Invalid Argument exception and 
               //return it in ErrorList
                E1MessageList returnMessages = new E1MessageList();
                returnMessages.addMessage(new E1Message(context, "018FIS", 
    invalidArgEx.getMessage()));
                return returnMessages;
            } catch (BSFNServiceSystemException systemEx) {
                //Create error message for System exception and return it in 
                //ErrorList
                E1MessageList returnMessages = new E1MessageList();
                returnMessages.addMessage(new E1Message(context, "019FIS", 
    systemEx.getMessage()));
                return returnMessages;
            }
           //set internal VO attributes based on values passed back from bsfn
           //Must cast object to appropriate data type coming from bsfnParams 
    collection.
           internalVO.setMnAddressBookNumber((MathNumeric)bsfnParams.
    getValue("mnAddressBookNumber"));
           internalVO.setSzLongAddressNumber((String)bsfnParams.
    getValue("szLongAddressNumber"));
           internalVO.setSzCountry((String)bsfnParams.getValue("szCountry"));
           internalVO.setSzBusinessUnit((String)bsfnParams.
    getValue("szBusinessUnit"));
           internalVO.setJdDateEffective((Date)bsfnParams.
    getValue("jdDateEffective"));
           E1MessageList messages = bsfnParams.getE1MessageList();
           //set prefix to the message list being returned to provide more 
    information on errors
           bsfnParams.getE1MessageList().setMessagePrefix("AB MBF N0100041");
           //return any errors, warnings, or informational messages to the 
           //caller
           return bsfnParams.getE1MessageList();
       }
    

When you run a business function, two exceptions, BSFNServiceInvalidArgException and BSFNServiceSystemException, are thrown. The generated code runs the business function within a try/catch block, and in the event that an invalid argument is passed to the business function, the error will be caught and added to the message list and returned to the caller. The same behavior occurs if a database exception occurs within the business function. This code sample shows a try/catch block:

try {
    //get bsfnService from context
    IBSFNService bsfnService = context.getBSFNService();
    //execute business function
    bsfnService.execute(context, connection, "AddressBookMasterMBF", 
bsfnParams);
} catch (BSFNServiceInvalidArgException invalidArgEx) {
   //Create error message for Invalid Argument exception and return it in 
ErrorList
    E1MessageList returnMessages = new E1MessageList();
    returnMessages.addMessage(new E1Message(context, "018FIS", 
invalidArgEx.getMessage()));
    return returnMessages;
} catch (BSFNServiceSystemException systemEx) {
    //Create error message for System exception and return it in ErrorList
    E1MessageList returnMessages = new E1MessageList();
    returnMessages.addMessage(new E1Message(context, "019FIS", 
systemEx.getMessage()));
    return returnMessages;
}