Author Topic: Creating Files with WS function  (Read 6559 times)

Sai Siddhartha

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 47
    • View Profile
Creating Files with WS function
« on: November 09, 2017, 07:47:26 AM »
Purpose:
To create file with WS function using ActiveXObject object.

Usage:
ActiveXObject adds support for the Microsoft COM objects. It enables user to utilize the local file system.
Using this functionality we can create a new file in any specified folder. It comes in handy if user wants to create any logfiles.

ActiveXObject requires the wsoffice.dll installed and loaded before making the call.

Below example demonstrates the creating of text file with filename as current date and time in a specified folder and add text to it.

Liquid UI Code:
////////////////////////////// SAPLIQS0.E0100.sjs ///////////////////////////

load("wsoffice.dll"); // loads wsoffice.dll file
onUIEvents['Enter'] = {"process":iw21_createfile}; //  executes function on clicking enter

function iw21_createfile(){
        var d = new Date();
        var fso  = new ActiveXObject("Scripting.FileSystemObject"); // creates activex object
        //creates file with current date and time as filename
        var fh = fso.CreateTextFile("C:\\guixt\\Files\\"+d.getFullYear()+""+(d.getMonth()+1)
        +""+d.getDate()+""+d.getHours()+""+d.getMinutes()+" "+d.getSeconds()+".txt", true);
         fh.WriteLine("some text goes here..."); // adds text to file
         fh.close(); // close created file
}

Navigate to path specified to view created files.

See attachment for screenshots