Sunday, March 21, 2010

Inserting Data in hidden detailed table after inserting in Master one

When working with a friend trying to insert data in a detailed table (without dropping the detailed table in a page view associated with its master table), and getting some of the detailed table column values from the same data inserted in the master table, we came across to use the following code:

public String insert_master_detail() {

        BindingContainer bindings = getBindings();
        OperationBinding operationBinding = 
        Object result = operationBinding.execute();
        //Perform a commit on the master table binding on page view
        if (operationBinding.getErrors().isEmpty()) {
        //if transaction succeeded then continue adding data to detail

        String amDeff = "model.AppModule";
        String config = "AppModuleLocal";
        ApplicationModule am =  
               Configuration.createRootApplicationModule(amDeff, config);
        ViewObject vo = am.findViewObject("DetailTabke1");
        //connect to the detail view using the application module 
       BindingContainer bc = 
       //get the current page bindings
        JUCtrlAttrsBinding Code = 
        JUCtrlAttrsBinding Name = 
       //get list of data added to the master table that will be add to 
        the detailed table
        NameValuePairs pairs = new NameValuePairs();
        Number n=new Number(1);
        pairs.setAttribute("No", n);
        pairs.setAttribute("Status", "00020");
        pairs.setAttribute("Typee", "051");
        pairs.setAttribute("StartDate", "1430/01/01");
        pairs.setAttribute("EndDate", "1430/01/01");
        Row ActivityTaskRow = vo.createAndInitRow(pairs);
        //create a Name value attribute and calling createAndInitRow
          with name value attributes for detailed table that will be 
          used to insert row in table
        //commit the transaction and then release the connection

        return null;

This code is added as an action to submit button and should be called after creating a new row in the master table.


  1. You shouldn't be creating a new application module - instead you should be using the existing one that is already out there.
    See the section:
    9.10.3 How to Access an Application Module Client Interface in a Fusion Web Application

    And you might want to wrap up your update as an AM Service method instead of coding it on the UI layer.

  2. Thanks for the advise, regarding application module you are right and you can get it for the binding container it self.

    This code was on the fly as a fast solution and it did the work!