JavaScript method: SCDatum.length()

This method returns the number of array elements in an array stored in a ITSMA Service Management Datum object. You can use this method to return the length of Service Management array fields, which are always stored as Datum objects. To query a particular array field in an SCFile object, use the following format: SCFile_object.array_field_name.length().

Note Replace any periods in the name of array_field_name with underscores. For example, you must convert the Service Management array field update.action to update_action when querying it from JavaScript.

Syntax

SCDatum_object.length();

Arguments

There are no arguments for this method.

Return value

A number and RC_SUCCESS or one of the other global return code values.

The method returns the number of array elements in an array stored in a Service Management Datum object and a global return code value of RC_SUCCESS or returns one of the error global return code values if the method cannot return the number of array elements.

Example

This example does the following:

  • Searches the probsummary table for any incident record you define in the search variable
  • Attempts to get the size of the returned SCFile object (the result is always zero)
  • Displays the contents of the action field (the action field contains Service Management array data)
  • Displays the size of the action field using the Service Management length() method
  • Converts the SCFile object into a JavaScript array using the Service Management toArray() method
  • Displays the size of the new JavaScript array using the core JavaScript length property
var incidentQuery;

function findIncidents( query )
{
 print( "Searching for incident records starting with " + query + "..." );
 var incidentFile = new SCFile( "probsummary" );
 var findIncident = incidentFile.doSelect( "number#\""+ query + "\"" );
 if ( findIncident == RC_SUCCESS )
 {
  print( "Success. Found incident records starting with " + query + ". The first record is:\n" + incidentFile );
  var objectSize = incidentFile.getSize();
  print( "Running the getSize() method on the returned SCFile object produces the following result: " + objectSize );
  var actionText = incidentFile.action;
  print( "The contents of the action field is:\n" + actionText );
  var actionSize = incidentFile.action.getSize();
  print( "The size of the action field is: " + actionSize );
  print( "Converting the SCFile object to a JavaScript array..." );
  var incidentArray = incidentFile.toArray();
  print( "The new JavaScript array is:\n" + incidentArray );
  var arraySize = incidentArray.length;
  print( "The size of the converted array is: " + arraySize );
	return incidentFile;
 }
 else
 {
  print( "Could not find incident records starting with " + query + ". " + RCtoString( findIncident ) );
  return null
 }
}

incidentQuery = "IM1005";
findIncidents( incidentQuery );