0

I have a little problem with trigger function on event in Google Apps Script. I try to run my function (in google apps script for spreadsheet) when I write a note in a specific cell. I tried onEdit() and onChange() events but neither worked.

Is there a way to trigger those functions when adding a Note to a cell?

I also want to run it when I change font style to italic, bold, or normal.

function onEdit(e) {
  var background = false;
  var range = e.range;
  var cell = range.getCell(1, 1);
  var output = cell.getNote();

    if(cell.getFontWeight() === 'bold') {
      cell.setBackground("#D6F4D9");
      background = true;
    } else if(cell.getFontWeight() === "normal") {
      cell.setBackground("#E4E8F3");
    }

    if(cell.getFontStyle() === "italic" && !background) {
      cell.setBackground("#FCE5CD");
    }


  if(output != undefined && output != "") {
     var numbers = output.split("\n");
     var result = 0;
    for(var k = 0, leng = numbers.length; k<leng; k++) {
      var num = numbers[k];
      num = num.split(" ");
      if(!isNaN(parseInt(num[0]))) {
       result += parseInt(num[0]);
      }

      if(k >= numbers.length-1) {
        if(!isNaN(result)) {
          cell.setValue(result+"zł");
        }
      }
    }
  }
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
PyxelCoder
  • 11
  • 2

1 Answers1

0

A list of things-that-don't-trigger-onEdit, along with their issue tracking ids, were provided in a previous answer.

Adding a note does not "edit" the content of a cell, so it won't trigger onEdit(). Likewise for onChange(); a note does not change the content of a cell.

I also want to run it when I change font style to italic, bold, or normal.

Formatting changes don't edit or change content; they will not trigger events either.

Community
  • 1
  • 1
Mogsdad
  • 44,709
  • 21
  • 151
  • 275