0

I'm using google spreadsheet scripting. I track my dispatches there. I created a button that when pressed uses the row you are in to create a calendar event. My current problem I'm working with is finding what type of task the event will be and the date. The 3 columns I'm working with are: Delivery, Integration, Training. All are dates. My first if else I'm assigning the date to a variable that will be used as the event start date/time. The second if else I'm assigning the task type to a variable to append to the event title.

My current error is: Missing ; before statement (line 15) - that is my first if

     function AddEvent() {

  var ss = SpreadsheetApp.getActiveSheet();
  var row = ss.getActiveRange().getRow();
  var rec = ss.getRange(row,2,1,28).getValues();
  var loc = ss.getRange(row,5).getValue();
  var ttl = ss.getRange(row,2).getValue();
  var typ;
  var stt;
  var del=ss.getRange(row,10).getValue();
  var int=ss.getRange(row,11).getValue();
  var trn=ss.getRange(row,12).getValue();

    //determine what date to use, del-delivery, int-integration, trn-training
    If (isBlank(trn)=False) {stt=trn};
    Else If (isBlank(int)=False) {stt=int};
    Else {stt=del};

    //I will append my event title with this value to know the task type
    If (isBlank(trn)=False) {typ="Training: "};
    Else If (isBlank(int)=False) {typ="Integration: "};
    Else {typ="Delivery: "};

Logger.log(stt, typ);


}
Rubén
  • 34,714
  • 9
  • 70
  • 166
Matthew
  • 25
  • 1
  • 10

2 Answers2

2

Short answer

Besides the reported error message the script has several errors. Bear in mind that Google Apps Script is based on JavaScript.

Syntax errors

Instead of

  • If the correct syntax is if
  • Else the correct syntax is else
  • Else If the correct syntax is else if
  • False the correct syntax is false

Comparisons

On Google Apps Script / JavaScript a single = is used to assign a value or object to a variable. Use == to make an abstract equality comparison and === to make a strict equality comparison.

Functions

On Google Apps Script / JavaScript there isn't a default isBlank() function. You have to declare it.

Rubén
  • 34,714
  • 9
  • 70
  • 166
-1

function AddEvent() {
    
  var ss = SpreadsheetApp.getActiveSheet();
  var row = ss.getActiveRange().getRow();
  var rec = ss.getRange(row,2,1,28).getValues();
  var loc = ss.getRange(row,5).getValue();
  var ttl = ss.getRange(row,2).getValue();
  var typ;
  var stt;
  var del = ss.getRange(row,10).getValue();
  var delib = ss.getRange(row,10).isBlank();
  var int = ss.getRange(row,11).getValue();
  var intib = ss.getRange(row, 11).isBlank();
  var trn = ss.getRange(row,12).getValue();
  var trnib = ss.getRange(row, 12).isBlank();

    //determine what date to use, del-delivery, int-integration, trn-training
  if (trnib == false) {stt=trn;}
  else if (intib == false) {stt=int;}
  else if (delib == false) {stt=del;}
  else return (Browser.msgBox('No valid date was found'));
    
    //I will append my event title with this value to know the task type
  if (trnib == false) {typ='Training: ';}
  else if (intib == false) {typ='Integration: ';}
  else {typ='Delivery: ';}
  
  Logger.log(typ + stt);
   
}
Matthew
  • 25
  • 1
  • 10
  • 1
    Code-only answers are not useful. At least provide an indication of what you changed, and why it solves your original issue. This will then offer future readers something of value. If this is just to reformat your existing, problem code, it should be done in an edit to the I original post. – tehhowch Apr 01 '18 at 12:22
  • I tried for 30 minutes to post my code inside my reply. I couldn't do anything to get it into the post. I tried the code button, I tried cntrl K, I tried 4 spaces, I tried 8 spaces. I tried deleting the post and starting from scratch. Nothing worked till I found the javascript console where I clicked the add to post. As I see now I apparently didn't un-delete my explanation. any idea why I could get my code in my post like I did in my first post? – Matthew Apr 01 '18 at 17:14
  • @Matthew : Try on the [Formatting Sandbox](https://meta.stackexchange.com/q/3122/289691) and if you still have problems post a [meta-tag:support] question on [meta]. – Rubén Apr 02 '18 at 13:42