Author Topic: Re-Order List to Remove Empty Rows  (Read 6428 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 96
    • View Profile
Re-Order List to Remove Empty Rows
« on: February 29, 2016, 11:41:24 AM »
Purpose:
To remove all the empty rows in a list and move the populated rows in Order.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// Function is called to remove blank spaces
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}

// Function is called to validate if the variable holds blank or null value
function isBlank(jvar){
   if(typeof jvar == 'string') {
      jvar = jvar.trim();
   }
   return(jvar == 'undefined' || jvar == null || jvar == "" || jvar == void 0);
}

// Move next available item in the list to blank row
function updateRows(){
   for(var i=1;i<z_endrow;i++){
      set('V[z_temp_mat]','&V[z_material_&V]');
      set('V[z_temp_qty]','&V[z_quantity_&V]');
      z_temp_mat = z_temp_mat.trim();
      z_temp_qty = z_temp_qty.trim();
      
      // Make Material required if Quantity is entered
      if((isBlank(z_temp_mat)) && (!isBlank(z_temp_qty))){
         return("E: Please enter Material for Item: "+i);
      }
      
      // Make Quantity required if Material is entered
      if((!isBlank(z_temp_mat)) && (isBlank(z_temp_qty))){
         return("E: Please enter Quantity for Item: "+i);
      }
         
      if((isBlank(z_temp_mat)) && (isBlank(z_temp_qty))){
         for(var j=i+1; j<z_endrow; j++){
            set("V[z_temp_next_mat]", "&V[z_material_&V[j]]");
            set("V[z_temp_next_quan]", "&V[z_quantity_&V[j]]");
            z_temp_next_mat = z_temp_next_mat.trim();
            z_temp_next_quan = z_temp_next_quan.trim();
            
            if(!isBlank(z_temp_next_mat) && !isBlank(z_temp_next_quan)){
               // Copy the available item to blank row
               set("V[z_material_&V]","&V[z_temp_next_mat]");
               set("V[z_quantity_&V]","&V[z_temp_next_quan]");
               
               // Set the location to be blank
               set("V[z_material_&V[j]]", " ");
               set("V[z_quantity_&V[j]]", " ");
               break;
            }
         }
      }
   }
}

// User Interface
del('X[IMAGE_CONTAINER]');      // Delete ActiveX Container on SAP Easy Access screen
del('P[User menu]');
del('P[SAP menu]');
del('P[SAP Business Workplace]');
del('P[Display role menu]');
del('P[Add to Favorites]');
del('P[Delete Favorites]');
del('P[Change Favorites]');
del('P[Move Favorites down]');
del('P[Move Favorites up]');
del('P[Create role]');
del('P[Assign users]');
del('P[Documentation]');

z_endrow = 12;                              // Update row count here
comment([1,1], "Item   Material          Quantity");      
for(item_counter=1; item_counter<z_endrow; item_counter++){         // Display 10 rows on UI
   inputfield([item_counter+1,1], {"name":"z_item_&V[item_counter]", "size":4, "readonly":"true", "alignright":"true", "nolabel":"true"});
   inputfield([item_counter+1,6], {"name":"z_material_&V[item_counter]", "size":18, "nolabel":"true"});      
   inputfield([item_counter+1,25], {"name":"z_quantity_&V[item_counter]", "size":10, "nolabel":"true"});
   set("V[z_item_&V[item_counter]]", item_counter);
}

pushbutton([TOOLBAR], "@0Z@Update Rows", '?', {"process":updateRows});   


See attachments for code samples!
« Last Edit: February 29, 2016, 11:43:30 AM by Benjamin Dasari »