Anil's Blog is Best Viewed on GOOGLE CHROME

Sunday, August 31, 2014

Find Duplicate Row OR Copy/Clone VO Row

This article will give you idea on how to restrict user to enter duplicate rows. The requirement came when we want to enhance the user experience by providing the functionality to allow multiple Tools issue at one time.

This is applicable to all pages having table region/ advance table region and you want to restrict the user from enetring duplicate row. Here please keep in mind that I am not comparing the VO rows with DB rows. 

Application Module Method

        public void checkDuplicateRow() {

        XxTestToolsVOImpl lo_tools = getXxTestToolsVO(); //Table View Object
        XxTestToolsVOImpl clonevo = 
            (XxTestToolsVOImpl)this.findViewObject("XxTestToolsVO2"); //Dummy VO for check duplicity 
        if (clonevo == null) {
   //Create Dummy VO
            clonevo = 

        Row[] sourceVORows = 
            lo_tools.getFilteredRows("SelectFlag", "Y"); //Picking only those row where the Checkbox is checked
        if (!(clonevo.isPreparedForExecution())) {
  //Create ClonveVO with SourceVO rows
        for (Row row: sourceVORows) {
            Row cloneRow = clonevo.createRow();
            cloneRow = row;
            clonevo.insertRowAtRangeIndex(clonevo.getRangeIndexOf(clonevo.last()) + 
                                          1, cloneRow);//Inserting row one after another
        int i = 0;
        int j;
   for (Row row: sourceVORows) {
                j = 0;
                for (clonevo.first(); j < clonevo.getFetchedRowCount(); 
                    if (i == j) {
                        continue; //Ignore the row where index is same.
// This loop compare 1st row with all the rows except 1st then second row will   all the rows except 2nd and so on.
        if ((row.getAttribute("SerialNumber") +"").equals((clonevo.getCurrentRow().getAttribute("SerialNumber"))+"") && (row.getAttribute("InventoryItemId") + "").equals((clonevo.getCurrentRow().getAttribute("InventoryItemId"))+"") && (row.getAttribute("LotNumber") + "").equals((clonevo.getCurrentRow().getAttribute("LotNumber")) +  "") && (row.getAttribute("SubinventoryCode") +  "").equals((clonevo.getCurrentRow().getAttribute("SubinventoryCode")) + "") &&  (row.getAttribute("Locator") + "").equals((clonevo.getCurrentRow().getAttribute("Locator")) + ""))
                  clonevo.remove(); //If the row is duplicate remove the dummy VO
                  throw new OAException("Row Number " + (i + 1) + " and " + (j + 1) + " is duplicate." + " Please select only unique Tools to issue");

Thanks, --Anil

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.