Do you find this script useful?
Yes
No
Comments?
Dynamic 'edited by'
This script uses the login name, the computer name, and the domain name, all retrieved with the Windows Script Host object (i.e., WSH has to be installed on the end users' machine), and places that info in an 'edited by' box on an edit form. The box is filled in only ONCE when the edit window is open, even if the user clicks SAVE several times before closing the edit window--Unless the form box is cleared, then it will fill it in again.
Script Language: JavaScript For use with:
DB/TextWorks
Requires at least version 4.0
// ======================================================
// CUSTOMIZABLE VARIABLES - this section includes global
// variables that you can change to meet your needs.
//
// Assign the script name shown below to the box in which
// you want the "edited by" information placed. Or, if you
// prefer, use a different script name and change the text
// in quotes below to match.
//
var targetBoxName = "EditedBy";

// Specifies that the new information should appear in a new
// entry at the top of the field, rather than replacing the
// old contents of the field.
//
var bSaveEditHistory  = true;

// Specifies that the current date should precede the username.
//
var bIncludeDateInLog  = true;

// Specifies that the domain and computer names should
// not be included.
//
var bIncludeDomainName  = false;
var bIncludeComputerName = false;

// END OF CUSTOMIZABLE VARIABLES
// ======================================================
// additional global variable
var bRecordSaved;

function onRecordOpen()
{
 bRecordSaved = false;
}

function onRecordSave()
{

 // these variables retrieve the information about
 // the current session (who's logged in on this machine,
 // this machines' domain, and name)Windows Scripting
 // Host object (WScript) must be installed for this to
 // work. WSH is available from Microsft. For information,
 // see http://msdn.microsoft.com/scripting/

 var WSHNetwork  = new ActiveXObject("WScript.Network");
 var szDomainName = WSHNetwork.UserDomain;
 var szComputerName = WSHNetwork.ComputerName;
 var szLoginName  = WSHNetwork.UserName;

 var szCurrentEditHistory; // holds the current information
                           // in the 'edited by' field
 var szNewEditHistory;  // holds the new information for
                        // the 'edited by' field

 var dtToday = new Date();    // get today's date from
                             // the local machine
 var szToday = dtToday.toLocaleString(); // today's date,
                  // formatted into local date time string

 var es = Application.entrySeparator;

 var tgtBox;
 tgtBox = Form.boxes(targetBoxName);  // box containing
                         // 'edited by' field

 if (tgtBox) // ensure that the box exists in this form
 {

  // update the 'edited by' field only once per editing
  // session (or always if the 'edited by' field is blank)
  // regardless of how many times we click 'save'
  // when the edit window is open.
  //
  if ( ( bRecordSaved ) && ( tgtBox.content != "") )
   return true;

  // option to preserve the current edit history
  if (bSaveEditHistory)
   szCurrentEditHistory = tgtBox.content;

  // option to save the domain name, which is part
  // of the login name
  if (bIncludeDomainName)
   szLoginName = szDomainName + "\\" + szLoginName;

  szNewEditHistory = szLoginName;

  // option to save the date along with the editor's information
  if (bIncludeDateInLog)
   szNewEditHistory = szToday + " by " + szNewEditHistory;

  // option to save the computer name
  if (bIncludeComputerName)
   szNewEditHistory = szNewEditHistory + " from " + szComputerName;

  // if we are saving history, and there is some, append
  // the saved information to the new value for the field
  if ( ( bSaveEditHistory ) && ( szCurrentEditHistory != "" ) )
   szNewEditHistory = szNewEditHistory + es + szCurrentEditHistory;

  tgtBox.content = szNewEditHistory;

  // set our 'record saved' flag to true
  bRecordSaved = true;
 }
 else
 {
  Application.Message("There is no box named '" +
                      targetBoxName +
                      "' on this form.");
 }
}

Notes: This script works only if Windows Script Host is installed on the user's machine. WSH is included with Windows 98, Windows ME, and Windows 2000. It can also be downloaded from http://www.microsoft.com/msdownload/vbscript/scripting.asp. The user can alter what gets saved along with the datestamp and login name by changing the default values of some boolean variables, or by updating the script to record other information. Note the user need only customize the setting of 'targetBoxName' in this script to match the box named on their own form. Nothing else has to be changed.
Submitted by Inmagic Staff on 11/30/2000

Powered by DB/Text WebPublisher, from Inmagic WebPublisher PRO