7 Replies Latest reply: Apr 30, 2012 6:47 AM by Manish RSS

    insert a new row in log table when update on view object

    Manish
      hi All,

      i have created approval System where i maintain log which is based on table(ApprovalLog) which contain attribute like (Agencycode,approve_status,approved_by,approved_date).

      and i have also create a view object which is based on (AgencyApproval) table. which is also contain field approval_status by default 'N'


      i create a jsf page using this view object and drag drop as adf table now i want when user change approve_status field and click on commit button then

      a new row created on to ApprovalLog table and values of column like (agencycode,approve_status,approved_by) comes from AgencyApproval table.

      How can i do this in ADF.

      Please Reply.

      manish
        • 1. Re: insert a new row in log table when update on view object
          Manish
          Is there any solution? please reply.


          thanks
          • 2. Re: insert a new row in log table when update on view object
            Timo Hahn
            It's weekend, what do you expect?

            you can overwrite the prepareForDML method of the AgencyApproval EO and in there get the other VO (ApprovalLog) and create the log row from there. Here is a sample:
                @Override
                protected void prepareForDML(int i, TransactionEvent aTransactionEvent)
                {
                    // mLogger.info("prepareForDML op:" + i);
                    // olny add something if hte operation is insert or update
                    if (i != EntityImpl.DML_DELETE)
                    {
                        String depName = this.getDepartmentName();
                        if (depName == null)
                            depName= "";
                        this.setDepartmentName(depName + "---");
                        DummyViewImpl vo = (DummyViewImpl)this.getDBTransaction().findViewObject("ApprovalLogView1"); // change it to the name of your VO
                        DummyViewRow row = (DummyViewRow)vo.createRow();
                        // set the values ...
                        row.setValue(getDepartmentId());
                        vo.insertRow(row);
                    }
                    super.prepareForDML(i, aTransactionEvent);
                }
            Timo
            • 3. Re: insert a new row in log table when update on view object
              Manish
              hi Timo,

              what is "DummyViewImpl" ?
              • 4. Re: insert a new row in log table when update on view object
                Timo Hahn
                DummyViewImpl is the test VO I used. You need to exchange this with theVO you use to log the records....


                Timo
                • 5. Re: insert a new row in log table when update on view object
                  Manish
                  hi Timo,


                  i have done this as following and it is working.

                  please tell me it is right approach or not.
                          protected void prepareForDML(int i, TransactionEvent aTransactionEvent)
                          {
                              if (i != EntityImpl.DML_DELETE)
                                     {
                                        
                                       ViewObjectImpl vo = (ViewObjectImpl)this.getDBTransaction().findViewObject("AdAgcrlimitAppLogView3"); // change it to the name of your VO
                                         Row row = vo.createRow();
                                         // set the values ...
                                         row.setAttribute("AppDt",getAppDt() );
                                         row.setAttribute("Publ",getPubl() );
                                         row.setAttribute("GrpAgcode",getGrpAgcode() );
                                         row.setAttribute("GrpAgsubcode",getGrpAgsubcode() );
                                         row.setAttribute("StaticCrlimit",getStaticCrlimit() );
                                         row.setAttribute("FixCrlimit",getFixCrlimit() );
                                         row.setAttribute("VarcrLimit",getVarcrLimit() );
                                         row.setAttribute("AdhocLimit",getAdhocLimit() );
                                         row.setAttribute("AdhocFr",getAdhocFr() );
                                         row.setAttribute("AdhocTo",getAdhocTo() );
                                         row.setAttribute("CrAlertLimit",getCrAlertLimit() );
                                         row.setAttribute("BillAmt",getBillAmt() );
                                         row.setAttribute("AdjAmt",getAdjAmt() );
                                         row.setAttribute("DbnAmt",getDbnAmt() );
                                         row.setAttribute("PayAmt",getPayAmt() );
                                         row.setAttribute("UnbillAmt",getUnbillAmt() );
                                         row.setAttribute("Status",getStatus() );
                                         row.setAttribute("AlertTag",getAlertTag() );
                                      row.setAttribute("CrlimitTag",getCrlimitTag() );
                                      
                                         row.setAttribute("Confirm",getConfirm() );
                                         row.setAttribute("ApproveRemark",getApproveRemark() );
                                         row.setAttribute("ApproveBy",getApproveBy() );
                                         row.setAttribute("ApproveDt",getApproveDt() );
                                         row.setAttribute("ApproveStatus",getApproveStatus() );
                                         row.setAttribute("ApproveHier",getApproveHier() );
                                         row.setAttribute("Usrname",getUsrname() );
                                         row.setAttribute("Usrid",getUsrid() );
                                         row.setAttribute("Usrdate",getUsrdate() );
                                         row.setAttribute("Cuser",getCuser() );
                                         vo.insertRow(row);
                                     }
                                     super.prepareForDML(i, aTransactionEvent);
                                     
                                     
                          }
                  • 6. Re: insert a new row in log table when update on view object
                    Timo Hahn
                    Well, this is how I would do it.
                    Looks like you copy the whole record into your log table. If this is what you want that's fine.

                    Timo