Author Topic: Liquid UI File Path Validation  (Read 7121 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 96
    • View Profile
Liquid UI File Path Validation
« on: August 07, 2017, 04:50:13 PM »
Purpose:
To check if File of any type exists in a specified path location.
Used for validation before/after performing additional steps.

Liquid UI Code:
----------------------------------------------------------------------------------------------------------------------------------------------
Script File Name: SAPMLSMTR_NAVIGATION.E0100.sjs
----------------------------------------------------------------------------------------------------------------------------------------------
// User Interface
load('wsoffice');         // Need to load this file to use for ActiveXObject
del("X[IMAGE_CONTAINER]");   // Clear the SAP Easy Access screen
text([1,1],"Enter File Path in the format- Directory:\\Folder1\\Folder2\\...\\Filename", {"comment":true});
inputfield([2,1], "File Path", [2,15], {"name":"z_file_path", "size":40, "maxlength":100});
inputfield([3,15], {"name":"z_file_path_res", "size":20, "nolabel":true});
pushbutton([2,60],"@8T@Validate File", "?", {"process":validateFileInPath, "using":{"p_type":z_file_path}});

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

// 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);
}

// File Validation in the path specified
function validateFileInPath(param){
   var str = "";
   if(isBlank(z_file_path)){
      message("E: Please enter the File Path");
      set("V[z_file_path_res]", "");
      enter("?");
      goto END;
   }   

   set("V[str]", param.p_type);
   str = str.replace(/\\/g,"\\\\");
   var fso = new ActiveXObject("Scripting.FileSystemObject");
   if(fso.FileExists(str)){      
      set("V[z_file_path_res]", "FILE EXISTS");
   } else{
      set("V[z_file_path_res]", "FILE DOES NOT EXISTS");
   }   
   enter("?");

   END:;   
}


See attachments for code samples!

« Last Edit: August 09, 2017, 11:27:11 AM by Benjamin Dasari »