onit
onit

Reputation: 2372

Bring cell content to Notes in Google Sheets via script

The following code works for hiding the rows once one column 12 meets certain criteria. Now, some rows on column 13 do have a lot of content and if the user is to see it all, they would have to stretch the row. I would like to copy this content to a note to be put on the same cell, so the user can read it more easily, while hovering over the cell.

The specific goal here is to have the note set on column 13 if its content has more than 50 characters.

Here's the working code for the hiding part. The line where we have .setNote is the one stopping me from moving forward:

function onOpen() {
    var s = SpreadsheetApp.getActive().getSheetByName('Atividades');
    s.getRange(9,12,s.getLastRow(),2)
        .getValues()
        .forEach(function (r, i) {
          if (r[0] === 'Concluído' || r[0] === 'Cancelado' || r[0] === 'Note') {
          s.hideRows(i + 9)
          if (r[1].length > 50){
          s.setNote(i + r[1])
          }
        }
})
}

Upvotes: 1

Views: 120

Answers (1)

Marios
Marios

Reputation: 27350

Explanation:

  • setNote() is a method of a cell, but you applied it to a range of cells.

  • Since your goal is to set the note on the column 13 and after the 9th row, then you need this:

    s.getRange(i+9,13).setNote(i + r[1])
    

Solution:

Try this instead:

function onOpen() {

    var s = SpreadsheetApp.getActive().getSheetByName('Atividades');
    s.getRange(9,12,s.getLastRow(),2)
        .getValues()
        .forEach(function (r, i) {
          if (r[0] === 'Concluído' || r[0] === 'Cancelado' || r[0] === 'Note') {
          s.hideRows(i + 9)
          if (r[1].length > 50){
          s.getRange(i+9,13).setNote(i + r[1])
          }
        }
})

}

Upvotes: 2

Related Questions