Domanda

Come faccio a fare la variabile "Partnum" non essere case sensitive. Quando eseguo il copione, non ci vorrà rilevare "ABCD" se io sto cercando "ABCD". Non sono sicuro di cosa fare.

 function doStuff() {
  var ss = SpreadsheetApp.getActiveSheet();

  var starting_row = 2; // starting row to scan for part# on column C

  // outer loop, loop over products sold
  for (var j=6;j<=16;j++) {
    var r = ss.getRange(j,2);
    // read inventory part number entered
    var partnum = r.getValue();
    if (!partnum) {
      continue; // attempt to skip over empty rows in the B6:B16 range
    }
    var partcount = parseInt(ss.getRange(j,1).getValue());
    if (isNaN(partcount) || partcount<=0) {
      // invalid quantity. skip.
      continue;
    }

//  Browser.msgBox("partnum = "+partnum);

    // get list of known part # from the spreadsheet
    var parts = ss.getRange(starting_row,3,9999,1).getValues();
    var found = false;
    for (var i=0,l=parts.length;i<l;++i) {
      if (parts[i]==partnum) {
        // we have found our part. grab inventory count cell.
        found = true;
        var count = ss.getRange(starting_row+i,1).getValue();
        if (count-partcount<0) {
          Browser.msgBox("Error: Inventory for part "+partnum+", is "+count);
        } else {
          // write back the count number for that part, decremented by 1.
          ss.getRange(starting_row+i,1).setValue(count-partcount);
//          Browser.msgBox("Inventory updated.");
        }
        break; // either way, we're done with that part.
      }
    }
    if (!found) {
      Browser.msgBox("Part# "+partnum+" not found.");

    }
  }

}
È stato utile?

Soluzione

Per l'amor di calrity, ecco la risposta. Anche se @Freddie fu il primo a parlarne.

// get list of known part # from the spreadsheet
var parts = ss.getRange(starting_row,3,9999,1).getValues();
var found = false;
for (var i=0,l=parts.length;i<l;++i) {
  if (parts[i]==partnum) {

diventa:

// get list of known part # from the spreadsheet
var parts = ss.getRange(starting_row,3,9999,1).getValues();
var found = false;
for (var i=0,l=parts.length;i<l;++i) {
  if (parts[i].toLowerCase()==partnum.toLowerCase()) { // <-- NOTE CHANGE HERE

Modifica Per i non-stringa di oggetti

// get list of known part # from the spreadsheet
var parts = ss.getRange(starting_row,3,9999,1).getValues();
var found = false;
for (var i=0,l=parts.length;i<l;++i) {
  if ((parts[i]+"").toLowerCase()==(partnum+"").toLowerCase()) { // <-- NOTE CHANGE HERE

grazie a Ombra guidata

Altri suggerimenti

forse è possibile utilizzare toUpperCase ()?

Ombra guidata si avvicinò con la risposta che risolto il mio problema

Se ((parti [i] + "") .tolowercase () == (partnum + "") .tolowercase ()) -

Grazie

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top