Facility Control

 View Only
  • 1.  Dashboard - Opening and Writing to external files

    Posted 08-06-2020 08:18

    Hi Dashboard Team,

    I'm wondering if there is documentation floating around on opening/writing external files from a panel? I'm looking at implementing some logging functionality in to some panels we have, ideally I'd like to:

    • When a button is pressed, get the current date/time
    • Open a file called ddmmyyyy_dashboardLog.log
    • Append a line to the end of it with the time, button that's pressed and maybe some other info
    • Ideally, if it is a new day, create a new file called ddmmyyyy_dashboardLog.log 

    Of course, I wouldn't expect someone to write that whole thing for me but if anyone has some example panels or documentation that can open and write to a file when a button is pressed, I can probably figure out the rest on my own (you may recognise my name from a previous life :-) )

    Thanks!

    Kevin



  • 2.  RE: Dashboard - Opening and Writing to external files

    Posted 08-06-2020 15:49

    The following page talks about how to get a timestamp from javascript:

     

    https://tecadmin.net/get-current-date-time-javascript/#:~:text=Current%20Time%20in%20JavaScript,%3Ai%3As%E2%80%9D%20format.&text=2-,var%20today%20%3D%20new%20Date()%3B,)%20%2B%20%22%3A%22%20%2B%20today

     

    Once you have the date in the format you want, then you can do something like the following:

     

      var fileOutput = ogscript.createFileOutput("log3.txt", true);

      var date = new Date();

      var message = date.getHours() +":" + date.getMinutes() + ":" + date.getSeconds() + "  message"

      fileOutput.writeString(message + "\n");

      fileOutput.close();

     

    If you are writing very frequently (like a few times a second), you probably don't want to open and close the file every time.    You could open the file when the panel loads, and then close it when the panel closes.

     

     


    #DashBoard


  • 3.  RE: Dashboard - Opening and Writing to external files

    Posted 08-06-2020 17:27

    That's great - thanks Ben!

    Kevin


    #DashBoard