Liquid UI - Documentation - 21.05 Validate file path

21.05 Validate file path


Prerequisites


Purpose

This article will explain how to determine if a file exists at a specified path, considering the SAP Easy Access screen as an example. We will guide you through the process of checking if a file path exists in the specified file path based on the file path entered in the input field.


User Interface

//Create this file inside your script folder for customizing the SAP Easy Access screen: SAPLSMTR_NAVIGATION.E0100.sjs
//Now, let's add the Liquid UI script to this file and save it.


Customization

  1. Delete the image container on the SAP Easy Access screen using the del command.
     
    // Deletes the image container on the SAP Easy Access screen
    del("X[IMAGE_CONTAINER]");
     
     
  2. Use the load command to add the wsoffice.dll file; this allows you to access the functions included in it.
     
    //loads wsoffice file
    load('wsoffice');
    
     
  3. Add a comment that notifies users to enter the file path as per the format shown in the image below.
     
    // Creates a notification
    text([1,1],"Enter File Path in the format- Directory:\\Folder1\\Folder2\\...\\Filename", {"comment":true});
     
     
  4. Add two input fields with the labels File Path, " " to enter the location of the required file path, and add a pushbutton with the label Validate File.
     
    //Creates input fields to enter the file path 
    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}); 
    //Adds a pushbutton to check the validate file path function 
    pushbutton([2,60],"@8T@Validate File", "?", {"process":validateFileInPath, "using":{"p_type":z_file_path}});
     

     
  5. Now, add the following Liquid UI script to this file and save it.
     
    // 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:; 
    }
    
     

SAP Process

  1. Refresh the SAP Easy Access screen. Enter the file path into the input field to see if the file exists in the specified path, then click the Validate File button. If the file exists, a success message will be displayed, as shown below.
     
     
  2. If the file does not exist, an error message is displayed, as shown below.
     
     

Can't find the answers you're looking for?