Liquid UI - Documentation - 19.27 Custom function to copy the file

19.27 Custom function to copy the file


Prerequisites


Purpose

Learn how to copy the contents of a file to another file using a custom function created with ActiveXObject. This can be achieved by creating a function that will make a call to the local file system and move a pre-specified file from its original location to a new location.
 

We'll demonstrate this using the SAP Easy Access screen and guide you through the following steps:

  1. Delete the image container on the SAP Easy Access screen
  2. Add a toolbar push button to initiate the copying process
  3. Add a function to copy the contents of one file to another


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 on the screen
    del("X[IMAGE_CONTAINER]");
     
     
  2. Add a toolbar push button labeled Copy File which executes a process called CopyFile, when clicked.
     
    // Creates a push button labeled Copy File that executes CopyFile process on click.
    pushbutton([TOOLBAR], "Copy File",{"process":CopyFile});
    
     
     
  3. Add a function to copy the contents of one file to another file. In the below function, we have created a new ActiveXObject named 'objCopy'. This object allows us to make calls to the file system through the wsoffice.dll. Using the methods of this new object, we can locate the desired file and copy its content to a new text file when the function is called using a push button.
     
    // Function to rename a file using ActiveXObject in SAP
    function CopyFile(){
    // Loads wsoffice.dll file
      load("wsoffice.dll");
      var objCopy, test;
    // Creates new objCopy ActiveXObject 
    objCopy = new ActiveXObject("Scripting.FileSystemObject"); //Copy the contents of the Book1 text file to Book2 text file test = objCopy.CopyFile("C:\\LiquidUI\\Book1.txt","C:\\LiquidUI\\Book2.txt",true); }
     
    Note: You need to place the wsoffice.dll file in your scripts folder.
     

SAP Process

  1. Refresh the SAP Easy Access screen and click the Copy File toolbar push button to initiate the function. You will see the content of the Book1.txt file is copied to the Book2.txt file, as shown below.
     
     

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