mardi 23 avril 2019

I can't seem to make else if statement work based on the results of isBlank

I am new to coding so forgive me if my problem seems obvious

I have created a UI for entering data into a google sheets database. The UI has a button that runs a script to copy text in the database. However, I don't want the script to run if the button is selected when the input cell is empty.

I have created a script that checks if the cell is empty (isBlank) and based on the return (true/false) I would like to copy text to database or not if false.

I have reviewed numerous examples if else-if statements and they seems to work.

So it seems that the issue is trying to use the return from isBlank. The else-if does not seem to recognize the 'true' or 'false'

See my code below

  function inputNotes() {
    var app = SpreadsheetApp;
    var targetSheet =           app.getActiveSpreadsheet().getSheetByName('ASSIGNED DONORS');
    var newNote = targetSheet.getRange(10, 1).getValue();
    var checkBlank = targetSheet.getRange(10, 1).isBlank(); 

  Logger.log("Is Blank?: ").log(checkBlank).log(newNote);
  return checkBlank;


  if(checkBlank = 'false')
  {
    var timeStamp = new Date();
    var donorID = targetSheet.getRange(4, 4).getValue();
    var donorName = targetSheet.getRange(3, 4).getValue();
    var newNote = targetSheet.getRange(10, 1).getValue();
    var teamName = targetSheet.getRange(6, 4).getValue();
    var noteInput = app.openById('URL').getSheetByName('NoteLog');
    noteInput.appendRow([donorID, donorName, newNote, timeStamp, teamName]);
    Logger.log(newNote);

    targetSheet.getRange(10, 1).clearContent(); 
  }

    else(checkBlank = 'true')
   {
     Logger.log("Is Blank");
   }

  }

The result seems to either inter empty data into the database or does nothing.

Any help would be greatly appreciated.

Thanks

Scott

Aucun commentaire:

Enregistrer un commentaire