JavaScript method: SCDatum.getSize()

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

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

Syntax

SCDatum_object.getSize();

Arguments

There are no arguments for this method.

Return values

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 Manager 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 Manager array data)
  • Displays the size of the action field using the Service Manager getSize() method
  • Converts the SCFile object into a JavaScript array using the Service Manager toArray() method
  • Displays the size of the new JavaScript array using the core JavaScript length property

This example requires the following sample data:

  • A valid incident record number (for example, "IM1005")
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 );