Purpose: The purpose of this script is to demonstrate how to automate the process of importing data into a Liquid UI table and efficiently clearing the table when required. It Dynamically populating the table with material data, including material numbers and descriptions. Clearing the entire table with a single action, resetting all fields for fresh input. Automatically updating and displaying the count of non-empty rows for better visibility and control.
Liquid UI Code:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Script File Name: SAPLSMTR_NAVIGATION.E0100.sjs
-----------------------------------------------------------------------------------------------------------------------------------------------------------
// Delete Image Container
del("X[IMAGE_CONTAINER]");
// Create a table with Material and Description columns
table([1,1],[18,27],{"name":"z_table","title":"Material Table","rows":15});
column('Material',{"table":"z_table","name":"z_mat","position":1,"size":7});
column('Description',{"table":"z_table","name":"z_desc","position":2,"size":15});
// Add push buttons for importing and clearing data
pushbutton([0,35],"Import Data", {"process":fnImportData});
pushbutton([1,35],"Clear Table", {"process":fnClearTable});
// Add an input field to display the row count
inputfield( [0,1], "Row Count", [0,13],{ "name":"z_rowcount", "size":2});
// Function to import data into the table
function fnImportData(){
var matData = [];
for(i=1; i<=15; i++){
matData.push({key:'232'+i, value:'Testing '+i});
}
// Populate the table with data
for(i=0; i<matData.length; i++){
z_table.z_mat = matData.key;
z_table.z_desc = matData.value;
}
message("S: Data Imported successfully.");
// Count non-empty rows
var nonEmptyRows = 0;
for (var k = 0; k < matData.length; k++){
if (z_table.z_mat[k] && z_table.z_mat[k].trim() !== ""){
nonEmptyRows++;
}
}
// Update the row count in the input field
println('\n\n\n\n No of row count is :'+nonEmptyRows+':');
set('V[z_rowcount]','&V[nonEmptyRows]');
}
// Function to clear the table
function fnClearTable() {
for (var i = 1; i <= 15; i++) {
set("cell[Material Table,Material," + i + "]", "");
set("cell[Material Table,Description," + i + "]", "");
}
// Reset the row count
set("V[z_rowcount]", "0");
message("S: Table cleared successfully.");
}