JavaScript method: SCDatum.unshift()

This method adds an entry to the beginning of a JavaScript array and returns the total number of entries in the array. If you apply this method to a ITSMA Service Management array object, then it adds the item but does not return the number of entries in the array. This method does not use the Service Management global return code values.

Syntax

SCDatum_object.unshift( arrayItem );

Arguments

The following arguments are valid for this method:

Argument Data type Description
arrayItem String This argument specifies the array item you want to add to a JavaScript array.

Return values

A number.

The method returns the number of items in the array.

Example

This example does the following:

  • Searches the probsummary table for any incident record you define in the search variable
  • Displays the new incident record as a text string
  • Converts the contents of the action field into a JavaScript array
  • Adds an item to the beginning of the JavaScript array and prints the total number of items in the array

This example requires the following sample data:

  • A valid value for the number field (for example, "IM1010")
  • An incident record with an action field value (for example, "IM1010")
var incidentID;

function findIncident( id )
{
 print( "Searching for Incident record: " + id + "..." );
 var incidentFile = new SCFile( "probsummary" );
 var rc = incidentFile.doSelect( "number=\"" + id + "\"" )
 if ( rc == RC_SUCCESS )
 {
  print( "Success. found Incident record:\n" + incidentFile.getText() );
  print( "Converting the action field to a JavaScript array..." );
  var a = incidentFile.action.toArray();
  print( "The action field array contains the following: " + a );
  print( "Unshifting array one entry..." );
  var unshifting = a.unshift( "First array item" );
  print( "The number of items in the array are: " + unshifting );
  print( "The action field array contains the following: " + a );
  return incidentFile;
 }
 else
 {
  print( "Could not find Incident record. " + RCtoString( rc ) );
  return null
 }
}

incidentID = "IM1010";
findIncident( incidentID );