Author Topic: Select Directory with WS Custom Function  (Read 3715 times)

Sai Siddhartha

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 47
    • View Profile
Select Directory with WS Custom Function
« on: July 27, 2017, 08:57:07 AM »
Purpose:
Using the select directory custom function with WS.

Prerequisites:
WSoffice.dll

Usage:
Select directory custom function chooses a directory from which users can select a file to be opened. This is very useful  when choosing an Excel or PDF file to open for bulk data transfer to SAP via WS office.The custom function code is as follows.

function selectDirectory() {
    var dirName = " ";
    dirvalue = readDirectory(0, "Please select a directory", 0);
    set('V[z_directory]', dirvalue);
}

The selectDirectory custom function calls a second custom function, the readDirectory function. This function is where the dialog box attributes are defined and this function must be called for a user to display dialog box.The code is as below.

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

   var aWshShell = new ActiveXObject("Shell.Application");
   var objFolder = aWshShell.BrowseForFolder(wHnd, strTitle, iOptions);
   objFolder = objFolder.ParentFolder.ParseName(objFolder.Title).Path;
   aWshShell = void 0;
   return objFolder;
 }

Example:
In this example, we will select a directory and output the directory name on the SAP easy access screen. To demonstrate this operation, please do the following.

Liquid UI Script
----------------------------------------------------------------
On 'SAPLSMTR_NAVIGATION.E0100.sjs script file
----------------------------------------------------------------


load('wsoffice.dll'); //enables wsoffice functionalities
del("X[IMAGE_CONTAINER]");
pushbutton([8,25], "Select Directory", "/0", {"process":selectDirectory});  //pushbutton to call 'selectDirectory' function
inputfield([6,1], "Directory", [6,15], {"name":"z_directory", "size":"50"}); // inputfield to show selected directory

function readDirectory(wHnd,strTitle,iOptions){                    //readDirectory custom function
   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;
}

function selectDirectory() {  //selectDirectory custom function
    var dirName = " ";
    dirvalue = readDirectory(0, "Please select a directory", 0);
    set('V[z_directory]', dirvalue);
  }


Note: wsoffice.dll should be installed and needs to be loaded using code below.
         load('wsoffice.dll');


See attachment for screenshots and more details
« Last Edit: July 28, 2017, 12:53:04 AM by poojitha.reddy@guixt.com »