Liquid UI - Documentation - 19.33 Custom function to start an application

19.33 Custom function to start an application


Prerequisites


Purpose

This article demonstrates how to create a custom function that enables users to launch a specific application. This is particularly helpful when selecting an Excel, Word, or PDF file for transferring data in bulk to SAP through 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 a pushbutton to open the Excel file
  3. Add a startAppExcel function
  4. Add a ReadDirectory function
  5. Add a startApplication 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 an image container on SAP Easy Access screen 
    del("X[IMAGE_CONTAINER]");
    
     
     
  2. Add a push button labeled Start Open Excel File that executes the startAppExcel process on click.
     
    // Creates a push button labeled Start Open Excel File and executes the startAppExcel process on click.
    pushbutton([6,1], "Start Open Excel File", "/0", {"process":startAppExcel});
    
     
     
  3. Add a startAppExcel function that calls the readDirectory custom function, which defines dialog box attributes and displays them.
     
    //Function to call the directory
     function startAppExcel(){
    load("wsoffice.dll");
    	var dirName = "";
    	var fileName = ["Integrated Steel Plant Info.xlsx"];
    	dirName = readDirectory(0,"Please select a directory",0);
    	set('V[z_search]', dirName);
    	startApplication(z_search + "\\" + fileName[0]);
    	} 
    
     
  4. Add a readDirectory custom function, to read the file directory path of a selected file.
     
    // 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
    	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;
    } 
    
     
  5. Add a startApplication function to launch an application with ActiveXObject.
     
    // Function to launch the application
    function startApplication(strFile,strParamStr){
    	//This function is for starting an application with parameters if specified
    	var aWshShell = new ActiveXObject("WScript.Shell");
    	if (strParamStr != null)
    		strFile = strFile + " -" + strParamStr;
    	aWshShell.run(strFile);
    } 
    
     

SAP Process

  1. Refresh the SAP Easy Access screen and click the Start Open Excel File push button. This action displays a Browse For Folder dialog window. Now select an Excel file and click OK.
     
     
  2. Once the file is found, the application will be launched successfully, as shown below.
     
     

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