Author Topic: Copytext - fromfile/tofile Options  (Read 2757 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 95
    • View Profile
Copytext - fromfile/tofile Options
« on: August 13, 2018, 04:44:35 PM »
Purpose:
Using copytext command to copy data from/to files.
Attached sample scripts uses external data to copy from file to textbox and vice-versa.

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});


Liquid UI Code:
----------------------------------------------------------------------------------------------------------------------------------------------
Script File Name: SAPLSMTR_NAVIGATION.E0100.sjs       // Easy Access
----------------------------------------------------------------------------------------------------------------------------------------------
// User Interface
clearscreen();
pushbutton([1,2], "Copy from File to Text", "?", {"size":[2,20], "process":procCopyTextFromFile});
pushbutton([1,25], "Clear Textbox", "?", {"size":[2,20],"process":procClearTextbox});
textbox([4,2],[15,80],{"name":"mytext1"});
pushbutton([17,2], "Copy from Text to File", "?", {"size":[2,20], "process":procCopyTextFromTextToFile});


// 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("?");
}


See attachments for code samples!
« Last Edit: September 27, 2019, 01:24:13 PM by Benjamin Dasari »