Liquid UI - Documentation - 19.08 Copytext - copying text to and from files

19.08 Copytext - copying text to and from files


Prerequisites


Purpose

In this article, you will learn how to copy text from an external file to the SAP and vice versa using the copytext command with fromfile, fromstring, tostring, totext, and appendfile options.

This is demonstrated using the SAP Easy Access screen and will walk you through the following steps:

  1. Delete the Image container on the SAP Easy Access screen
  2. Add three push buttons to copy text to and from files
  3. Add a function to execute copy operations
     
Note: Available from LUI Desktop Version 1.2.333.0 and LUI Server Version 3.5.571.0


Syntax

copytext({"fromfile":filename,"totext":textboxname});
copytext({'fromstring':stringname,'tofile':filename});
 

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 textbox to display the text copied from a file.
     
    // Creates a textbox to display the text
    textbox([4,2],[15,80],{"name":"mytext1"});
    
     
     
  3. Add three push buttons labeled Copy from File to Text, Clear Textbox, and Copy from Text to File to copy text to and from files and a textbox.
     
    //Creates a push button labeled “Copy Text from File.”
    pushbutton([1,2], "Copy from File to Text", "?", {"size":[2,20], "process":procCopyTextFromFile});
    //Creates a push button labeled “Clear textbox.”
    pushbutton([1,25], "Clear Textbox", "?", {"size":[2,20],"process":procClearTextbox});
    //Creates a push button “ Copy from text to File”
    pushbutton([17,2], "Copy from Text to File", "?", {"size":[2,20], "process":procCopyTextFromTextToFile});
    
     
     
  4. Add a function to execute the copy operations.
     
    // Function to convert text(single or multi-line) to array
    function convertTextToArray(inpText) {
       var outArr = [];
       outArr = inpText.split('\n');
       return outArr;
    }
    
    // Function to clear textbox
    function procClearTextbox(){
       var strBlank = "";   
       copytext({"fromstring":"strBlank","totext":"mytext1"});
    }
    
    // Function to copy data from file to Liquid UI textbox
    function procCopyTextFromFile(){
       set("V[NotifData]","Notifications.txt");
       
       onscreen "SAPLSMTR_NAVIGATION.0100"
          copytext({"fromfile":"&V[NotifData]","totext":"mytext1"});
          enter('?');
    }
    
    // Function to copy data from textbox to file
    function procCopyTextFromTextToFile(){
       set("V[mystr]","Testing copytext fromstring tofile options");
       set("V[myfile1]","C:\\LiquidUI\\Scripts\\TestFile.txt");
       //Below line opens and clears the file or creates a new file if it does not exist
       openfile("&V[myfile1]",{"output":true});
       closefile("&V[myfile1]");
          
       onscreen "SAPLSMTR_NAVIGATION.0100"
          // Below line to copy string to file
          // copytext({'fromstring':'mystr','tofile':'&V[myfile1]'});
          
          // Below lines to convert user entered text in
          // textbox to array and then use copytext to copy to file
          arrInp = [];
          arrInp = convertTextToArray(mytext1);
          for(var i=0;i<arrInp.length;i++) {
             var textString = arrInp;
             textString = textString.replace('\r','');
             copytext({'fromstring':'textString','tofile':'&V[myfile1]','appendline':true});
          }   
          enter("?");
    }
    

    Notifications.txt

    --------------------------------------------
    --------------------------------------------
    |  S|Notifctn|Notif.date|Description       |
    --------------------------------------------
    |   |10006137|06/15/2018|Test Kohler 1     |
    |   |10006138|06/15/2018|Test Kohler       |
    |   |10006147|06/18/2018|Test Kohler Server|
    |   |10006148|06/18/2018|Test Kohler Ipad  |
    |   |10006150|06/18/2018|Test Kohler 4     |
    |   |10006151|06/18/2018|test Android      |
    |   |10006155|06/19/2018|Test Kohler Ipad 1|
    |   |10006158|06/20/2018|dafrerer          |
    |   |10006172|07/27/2018|reonfdfd          |
    |   |10006175|08/01/2018|Testong onfd      |
    |   |10006193|08/08/2018|test              |
    |   |10006194|08/08/2018|test              |
    --------------------------------------------
    
    Note: You need to place above two files in your scripts folder to run the scenario.
     

SAP Process

  1. Refresh the SAP Easy Access screen. Click Copy from File to Text to copy external file content into the textbox.
     
     
  2. Click Clear Textbox to delete the content from the textbox.
     
     
  3. Click Copy from Text to File to copy content from the textbox to an external file.
     
     

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