Learn about how to summary data from all one to many records after save child entity.

Requirement

System must summary total amount of all Supplier records to Summary Price of Oder Request Item.

Procedure

  1. From ONEWEB workspace, open java file name "com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode" and override method "modifyResult()" with coding below.


@Override

       public Vector modifyResult() {

               //Current child entity

               HashMap currentRequestItemData = EAFManualUtil.getDataHashMapFromSession("MD9443222701", request);

               String currentOrderItemID = (String)currentRequestItemData.get("ORDER_ITEM_ID");

               String currentOrderItemSummary = (String)currentRequestItemData.get("SUMMARY_PRICE");

               

               //One to many before open child entity

               MasterFormHandler orderItemForm = (MasterFormHandler)getRequest().getSession().getAttribute("MD1290242832_session");

               Vector vForm = orderItemForm.getStoreActionList();

               logger.debug("#####vForm#####"+vForm);

               double sumPrice = 0;

               for (int i=0; i<vForm.size(); i++) {

                       HashMap hData = EAFManualUtil.getDataHashMapFromSession("MD1290242832", request, i);

                       logger.debug("#####hData#####"+hData);

                       

                       String recordOrderItemId = (String)hData.get("ORDER_ITEM_ID");

                       String recordSummary = (String)hData.get("SUMMARY_PRICE");

                       

                       //Summary all record except editing record (current child entity is editing record)

                       if(!currentOrderItemID.equals(recordOrderItemId)){

                               if(recordSummary != null && !"".equals(recordSummary)){

                                       sumPrice += Double.parseDouble(recordSummary);

                               }

                       }

                       logger.debug("#####recordSummary#####"+recordSummary);

                       logger.debug("#####sumPrice#####"+sumPrice);                        

               }

               

               //Plus editing data to summary

               sumPrice += Double.parseDouble(currentOrderItemSummary);

               

               HashMap mainRequestData = EAFManualUtil.getDataHashMapFromSession("MD7333074691", request);

               

               Vector resultForProcess = getResultForProcess();

               

               HashMap serviceRequestDataHash = new HashMap();

               serviceRequestDataHash.put("TOTAL_AMT", String.valueOf(sumPrice));

               serviceRequestDataHash.put("REQUEST_ID", mainRequestData.get("REQUEST_ID"));

               

               Vector moduleKeyVect = new Vector();

               moduleKeyVect.add("REQUEST_ID");

               

               HashMap serviceRequestHash = new HashMap();

               serviceRequestHash.put("WF_SERVICE_REQUEST", serviceRequestDataHash);

               serviceRequestHash.put("MODULE_FIELD_KEY", moduleKeyVect);

               

               HashMap updateServiceRequestHash = new HashMap();

               updateServiceRequestHash.put("UPDATE", serviceRequestHash);

               

               resultForProcess.add(updateServiceRequestHash);

               

               logger.debug("#####resultForProcess#####"+resultForProcess);

               

               return super.modifyResult();

       }


    1. Go to App Designer and open entity "Doc Order Request - Back Office" then click edit at module "Order Request Item" and find module id at property name "Module ID".
    2. Replace "MD1290242832_session" with module id from step 1.1 (concatenate module id with "_session").
    3. Replace "MD1290242832" with module id from step 1.1.
    4. Go to App Designer and open entity "Doc Order Request - Back Office" then click edit at module "Order Request" and find module id at property name "Module ID".
    5. Replace "MD7333074691" with module id from step 1.4.
    6. Go to App Designer and open entity "Doc Order Request Item- Back Office" then click edit at module "Order Item" and find module id at property name "Module ID".
    7. Replace "MD9443222701" with module id from step 1.6


  1. Go to App Designer and open entity "Doc Order Request - Back Office" then click edit at entity action "UPDATE".
    1. On Action Field Configuration put "com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode" to Class Action.
    2. Click OK.
    3. Click Save this Entity.


  1. From ONEWEB workspace, export EafMasterEar.ear and deploy update to server. The class name "com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode" will update to server.


  1. Test by log in to FrontWeb.
    1. Login with Back Office user.
    2. Go to To Do List and claim job.
    3. Click edit Order Item.
    4. Click edit Supplier and save.
    5. Click save at child entity.
    6. System must summary  Summary Price to Total Amt.