Example: Getting a list of logged-on users

This JavaScript example accesses the built in system.users object to get an XML list of all the currently logged-on users on the system. It then loops through to access each individual user, and then prints the name (XML tag) and value of each field.

var usersXML = system.users;

If you uncomment the line of code, recompile, and then run the script again, you can view the suppressed output. It prints all logged-on users as a large XML document.

//print( usersXML );

This part of the script loops through to process each <user> element within <users>.

for ( userIndex in usersXML )
{
  var userXML = usersXML[userIndex];

If you uncomment the line of code, recompile, and then run the script again, you can view the suppressed output. It prints an individual user as an XML document.

//print( userXML );

This part of the script loops through to process each XML element node within the <user> element.

for ( fldIndex in userXML )
  {
    var node = userXML[fldIndex];

    print( node.getName() + ": " + node.getValue() );
  }
}