Prerequisites
- Products: Liquid UI WS, Liquid UI Server or Local DLL, Client Software
- Commands: inputfield(), del(), set(), pushbutton(), return()
- Files: wsoffice.dll
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.
- Delete the Image Container on the SAP Easy Access screen
- Add an input field to display the file path
- Add a toolbar push button to retrieve the file path
- Add a selectDirectory function
- 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
- Delete the image container on the SAP Easy Access screen using del().
// Deletes the image container del("X[IMAGE_CONTAINER]");
- 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});
- 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});
- 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); }
- 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
- Refresh the SAP Easy Access screen and click the Select Directory push button. This action opens the Folder’s dialog box, as shown below.
- 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.