dataSetApp.js
/**
* Validates that the species are found in the PData_Properties named range and returns an array of the row indexes for the species.
*
* @customfunction
*/
Validates that the species are found in the PData_Properties named range and returns an array of the row indexes for the species.
Validates that the species are found in the PData_Properties named range and returns an array of the row indexes for the species .
function validateSpecies(Species){
  try{
    var liquidsExist = false
    var liquidsIndex = 0
    var numberOfSpecies = 0
    var speciesArray = []
    var pDataArray = []
    var speciesIndexes = []
    var myErrorMsg = ""
    var fcnName = "validateSpecies"
    var sizeArray = []
    var curSpecies = ""
    var speciesFound = false
    var arLength = 0
    if(!validateWorkbook()){
      myErrorMsg = "There is something wrong with the PData workbook"
      throw new Error("Function name: " + fcnName + ", " + myErrorMsg);
    }
    pDataArray = SpreadsheetApp.getActiveSpreadsheet().getRangeByName("PData_Properties").getValues()
    speciesArray = Species.slice(0)
    sizeArray = size(speciesArray)
    if (typeof (Species) === "string" ) {            
      arLength = 1
    }else{
      arLength = speciesArray.length
    }
    for(var i = 0; i < arLength; i++){
      speciesFound = false
      if (sizeArray[i][0 ] === true && sizeArray[i][1 ] === 1) {
        curSpecies = speciesArray[i].toString();
      }else{
        if(sizeArray[i][1 ] !== false){
          if (sizeArray[i][2 ] === false) {            
            curSpecies = speciesArray.toString();
          }
        }else{
          return "The species parameter must be a single dimensional range." 
          throw new Error("Function name: " + fcnName + ", " + myErrorMsg);
        }
      }
      for(var j = 0; j < pDataArray.length; j++){
        if(curSpecies.toString() === pDataArray[j][0].toString()){
          speciesIndexes.push(j)
          speciesFound = true
          j = pDataArray.length - 1
        }
      }
      if(speciesFound === false){
        speciesIndexes.push("not found")
      }
    }
    return speciesIndexes
  }catch(myErrorHandler){
    return myErrorHandler.message
  }
}
function validateSpecies ( Species ) { try { var liquidsExist = false var liquidsIndex = 0 var numberOfSpecies = 0 var speciesArray = [ ] var pDataArray = [ ] var speciesIndexes = [ ] var myErrorMsg = "" var fcnName = "validateSpecies" var sizeArray = [ ] var curSpecies = "" var speciesFound = false var arLength = 0 if ( ! validateWorkbook ( ) ) { myErrorMsg = "There is something wrong with the PData workbook" throw new Error ( "Function name: " + fcnName + ", " + myErrorMsg ) ; } pDataArray = SpreadsheetApp . getActiveSpreadsheet ( ) . getRangeByName ( "PData_Properties" ) . getValues ( ) speciesArray = Species . slice ( 0 ) sizeArray = size ( speciesArray ) if ( typeof ( Species ) === "string" ) { arLength = 1 } else { arLength = speciesArray . length } for ( var i = 0 ; i < arLength ; i ++ ) { speciesFound = false if ( sizeArray [ i ] [ 0 ] === true && sizeArray [ i ] [ 1 ] === 1 ) { curSpecies = speciesArray [ i ] . toString ( ) ; } else { if ( sizeArray [ i ] [ 1 ] !== false ) { if ( sizeArray [ i ] [ 2 ] === false ) { curSpecies = speciesArray . toString ( ) ; } } else { return "The species parameter must be a single dimensional range." throw new Error ( "Function name: " + fcnName + ", " + myErrorMsg ) ; } } for ( var j = 0 ; j < pDataArray . length ; j ++ ) { if ( curSpecies . toString ( ) === pDataArray [ j ] [ 0 ] . toString ( ) ) { speciesIndexes . push ( j ) speciesFound = true j = pDataArray . length - 1 } } if ( speciesFound === false ) { speciesIndexes . push ( "not found" ) } } return speciesIndexes } catch ( myErrorHandler ) { return myErrorHandler . message } }
Validates that the species are found in the PData_Properties named range and returns an array of the row indexes for the species.
Validates that the species are found in the PData_Properties named range and returns an array of the row indexes for the species .
/* arrayTest */ /* valueORlength1 */ /* arrayTest */ /* arrayTest */