Scenario 2

This scenario uses an auto commit connection to create a default transaction by calling startPublishedMethod and passing an additional parameter that specifies the auto commit connection—startPublishedMethod(context,"processSalesOrder",IConnection. AUTO). Because inventory records are committed before the sales order is committed, an error could occur during the continued processing of the sales order. If an error occurs, another business function (referred to as a compensating business function) must be called to undo the inventory updates.

To control the transaction and handle a sales order failure, you use a manual commit connection to call the Sales Order Commit business function. Everything within the business function call will roll back. You can call a compensating business function to roll back the inventory records that were automatically committed. You want the default auto commit transaction to call the compensating business function.

This code sample illustrates this scenario:

public E1MessageList processSalesOrder(IContext context, IConnection 
connection, InternalProcessSalesOrder internalVO){
 ...   
       
        //call method (created by the wizard), which then executes 
Business Function or Database operation
           E1MessageList invMessages =  callInventoryMBF(context, 
                                                         connection, 
                                                         internalVO, 
                                                         programId);
           //add messages returned from E1 processing to business 
           //service message list.
           messages.addMessages(invMessages);
           if (!invMessages.hasErrors()) {
              //No errors continue processing SO using manual commit 
              //connection
           IConnection soConnection = context.getNewConnection
(IConnection.MANUAL);
           try {
                     //Call  SO 
                     E1MessageList soMessages = callSOMBF(context, 
                                                       soConnection, 
                                                       internalVO);
                     //Check for errors, collect in messages.
                     if (!soMessages.hasErrors()) {
                        soConnection.commit();
                     }else{
                        soConnection.rollback();
              //Errors in SO processing, call MBF to compensate for 
              //added inventory
              E1MessageList compMessages = callInventoryCompensateMBF
(context,connection,internalVO);
                        if(compMessages.hasErrors()){
                           compMessages.setMessagePrefix
("Unable to Compensate for Added Inventory");
                        } 
                        messages.addMessages(compMessages);
                     }
                  } 
                  catch (BSSVConnectionException e) {
                     //Create new error and return E1MessageList
                     E1Message txMessage =  new E1Message
(context, "006FIS",  e.getMessage());
                     messages.addMessage(txMessage);
                  }
                  soConnection.close();
                         
          }
     finishInternalMethod(context, "addAddressBook");
     return messages;
  }