Do you find this script useful?
Yes
No
Comments?
Alphabetize multiple entries in a field
When a record is saved this script will take the multiple entries in the field and place them in alphabetical order. The script will work for one or more boxes. Intended for use in an Edit window.
Script Language: JavaScript For use with:
DB/TextWorks
Requires at least version 4.0
// Change the box names in the following array to match the
// script names of boxes in your form. Add as many box names to
// the array as needed, following the format shown (box names
// in quotes, separated by commas).

var sortBox = new Array("box1","box2");

function onRecordSave()
{
  var i;
  var es = Application.entrySeparator;
  var fieldBox;         // box object
  var fieldString;      // contents of the box
  var entryArray;       // array of field entries

  // This loop will sort the entries in each box listed
  // above, individually.
  for (i = 0; i < sortBox.length; i++)
    {
    fieldBox = Form.boxes(sortBox[i]);
    if (fieldBox)     // ensure that the box exists
      {
      fieldString = fieldBox.content;
      entryArray = fieldString.split(es);

      // sort the entries using the JScript sort method
      entryArray = entryArray.sort();
      fieldString = entryArray.join(es);
      fieldBox.content = fieldString;
      }
    }

}
Notes: This script uses alphabetic filing for the sort. It will not work as desired on dates or numbers. The key to working with multiple entries is to split the value in the field into an Array with the Application.entrySeparator object. Once this is done it is a simple matter to use the JScript Array sort() method to put the entries in alphabetical order. The complete JScript reference on arrays can be found at http://msdn.microsoft.com/scripting/default.htm?/scripting/jscript/doc/jsobjarray.htm
Submitted by Inmagic Staff on 11/30/2000

Powered by DB/Text WebPublisher, from Inmagic WebPublisher PRO