JavaScript method: SCDatum.shift()

This method removes the first element from a JavaScript array and returns the element removed as a string. This method does not use the ITSMA Service Management global return code values.

Syntax

SCDatum_object.shift();

Arguments

There are no arguments for this method.

Return values

A string.

The method returns the element removed from 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 action field into a JavaScript array
  • Adds an item to the end of the array and displays the total number of elements in the array
  • Removes an item from the beginning of the array and displays the array item removed

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( "Pushing new array entry..." );
  var addOne = a.push( "First array item" );
  print( "The number of items in the array are: " + addOne );
  print( "The action field array contains the following: " + a );
  print( "Shifting array one entry..." );
  var removeOne = a.shift();
  print( "The array item removed was: " + removeOne );
  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 );