Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
142 views
in Technique[技术] by (71.8m points)

javascript - How to fix cell history in cell note?

I found a script that's supposed to add cell history in a note, the original one found here(https://www.pbainbridge.co.uk/2019/07/add-note-to-cell-on-google-sheet-edit.html) does not work or I'm doing something wrong. I modified the script and is supposed to add notes to cells in Column 18(R) seems to work but only on one of my sheets and it works properly only on page 2, in page 1 it makes a note but with no content other than date. Any help to fix is greatly appreciated!

function onEdit(e){
  if (e.range.getColumn() === 18) {
      var ss = e.source; 
      var sheet = ss.getSheets()[0];
      var range = e.range;
  var activeCell = sheet.getActiveCell();
  var currentCellValue = activeCell.getValue();
  var currentCellNote = activeCell.getNote();
  Logger.log('Current cell value is: ' + currentCellValue);
   
  Logger.log('Current Note contains: ' + currentCellNote);
 range.setNote('Last Modified: ' + new Date() + '
' + 'Cell Value: ' + "'" + currentCellValue + "'" + '

' + currentCellNote);
    
  }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
function onEdit(e){
  const sh=e.range.getSheet();
  const A1=sh.getRange(e.range.rowStart,e.range.columnStart).getA1Notation();
  const rg=sh.getRange(e.range.rowStart,18);
  const dt=Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM/dd/yyyy HH:mm:ss")
  const newNote=Utilities.formatString('Last Modified:%s cell:%s Value:%s
',dt,A1,e.value);
  rg.setNote(rg.getNote() + newNote);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...