Monday, 10 December 2012

Code to add values to child table


public void childvalue(String res_Name,String User){
            long parentformkey;
            try {
                  parentformkey = moform.getProcessFormDefinitionKey(getProcessInstKeyOfRes(res_Name,getUserKey(User)));
                  int parentformver = moform.getProcessFormVersion(getProcessInstKeyOfRes(res_Name,getUserKey(User)));
                  tcResultSet childforms = moform.getChildFormDefinition(parentformkey, parentformver);

                  for (int childFormCounter = 0; childFormCounter < childforms.getRowCount(); childFormCounter++) {
                      childforms.goToRow(childFormCounter);
                      String childTableName = childforms.getStringValue("Structure Utility.Table Name");
                      System.out.println(childTableName);
                      if (childTableName.equals("UD_CHFORM")) {
                  //    long formkey = childforms.getLongValue("Structure Utility.Child Tables.Child Key");
                  //    tcResultSet childFormData = moform.getProcessFormChildData(formkey, getProcessInstKeyOfRes(res_Name,getUserKey(User)));
                        //long childFormKey =0;



                        System.out.println(childforms.getRowCount());
                        for (int k = 0; k < childforms.getRowCount(); k++) {
                              childforms.goToRow(k);

                              long childFormKey = childforms.getLongValue("Structure Utility.Child Tables.Child Key");
                              HashMap<String, String> memberMap = new HashMap<String, String>();
                              HashMap<String, String> memberMap1 = new HashMap<String, String>();

                              memberMap1.put("UD_CHFORM_LOCATION","newvalue1");
                              memberMap.put("UD_CHFORM_LOCATION","newvalue2");
                              moform.addProcessFormChildData(childFormKey,getProcessInstKeyOfRes(res_Name,getUserKey(User)), memberMap);
                              moform.addProcessFormChildData(childFormKey,getProcessInstKeyOfRes(res_Name,getUserKey(User)), memberMap1);
                              System.out.println("added");

                            }
                      }
                  }



            } catch (tcAPIException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcProcessNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcFormNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcNotAtomicProcessException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcVersionNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcVersionNotDefinedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcColumnNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcRequiredDataMissingException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            } catch (tcInvalidValueException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
            }

      }