Using setNote in custom function causes permissions error [duplicate]

I’m using Apps Script to make a custom function that sets the note of a specific cell in a spreadsheet, but I’m getting the error “Exception: You do not have permission to call setNote,” even though the cell that’s being targeted is the same cell that’s calling the function. My code is:

var ss = SpreadsheetApp.getActive(); 
var sh = ss.getSheetByName("Sheet1"); 

function setCellNote(targRow, targCol, text, display) { 
  var cell = sh.getRange(targRow, targCol);
  cell.setNote(text); 
  return display;
}

and the call in the sheet is in cell A2 as =setCellNote(ROW(A2),COLUMN(A2),"test", "done")

I’ve tried using A1 notation, but I had to have the cell reference in quotes (meaning =setCellNote("A2"),...), and I need this to work across many cells, so the actual cell reference needs to automatically change as I copy the formula across many cells.