Liquid UI - Documentation - 19.32 Custom function to select a directory

19.32 Custom function to select a directory


Prerequisites

Purpose

In this article, you will learn how to create a custom function for selecting files from a directory. It is useful for choosing Excel, Word, or PDF files to transfer data in bulk to SAP using WS Office.

This is demonstrated using the SAP Easy Access screen and will guide you through the following steps.

  1. Delete the Image Container on the SAP Easy Access screen
  2. Add an input field to display the file path
  3. Add a toolbar push button to retrieve the file path
  4. Add a selectDirectory function
  5. Add a readDirectory function


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 the above file and save it.


Customization

  1. Delete the image container on the SAP Easy Access screen using del().
     
    // Deletes the image container
    del("X[IMAGE_CONTAINER]");
    
     
     
  2. Add an input field labeled Search to display the retrieved file path.
     
    // Creates an inputfield at row 2 and column 1 position on the screen with Search as its label name and z_search as its technical name 
    inputfield([2,1],"Search",[2,10],{"name":"z_search","size":40});
    
     
     
  3. Add a push button labeled Select Directory that executes the selectDirectory process on click.
     
    // Creates a push button labeled Select Directory that executes selectDirectory process on click.
    pushbutton([6,1], "Select Directory", "/0", {"process":selectDirectory});
    
     
     
  4. Add a selectDirectory function to call readDirectory and define the dialog box attributes.
     
    // Function to select the directory
    function selectDirectory() {
    	var dirName = " ";
    	dirvalue = readDirectory(0, "Please select a directory", 0);
    	set('V[z_search]', dirvalue);
    } 
    
     
  5. Create a custom function to access and use when SAP users invoke the selectDirectory command and need to read a directory.
     
    // Function to read the directory
    function readDirectory(wHnd,strTitle,iOptions){
    	//This function is for selecting a directory
    	//BIF_browseincludefiles
    	//the use of this option enables the selection of file in select directory dialog box
    load("wsoffice.dll"); var aWshShell = new ActiveXObject("Shell.Application"); var objFolder = aWshShell.BrowseForFolder(wHnd, strTitle, iOptions); objFolder = objFolder.ParentFolder.ParseName(objFolder.Title).Path; println("-------Specified Directory--------" + objFolder + "--------"); aWshShell = void 0; return objFolder; }
     

SAP Process

  1. Refresh the SAP Easy Access screen and click the Select Directory push button. This action opens the Folder’s dialog box, as shown below.
     
     
  2. Select the desired file and click OK. The chosen directory will be selected and the file path will be populated into the Search input field, as shown below.
     
     

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