Good Day experts.
I am not a very experienced person in this field but have been playing for over 4 days to get this right and am still hitting my head against the wall trying to find a solution.
I have read so many suggestions out there and all seem to have the same issue with security and privacy of google and user emails.
So my new thinking was to rather extract the data from the html container div.docs-blameview-author and div.docs-blameview-timestamp and paste that in row A.
This would happen after edit from any cell within a row.
Sadly I am not winning with this thinking even although I think my script is correct so am hopeful one of the experts can assist in where I am going wrong.
I do appreciate this is not the most stable approach due to google maybe changing their containers but for now I think it might be the cleanest and easiest way to provide the data I am trying to get.
user and date of last edit of a row.
function onEdit(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() !== 'Sheet1') {
return;
}
var row = e.range.getRow();
var rowIndex = row - 1;
var spreadsheetId = SpreadsheetApp.getActiveSpreadsheet().getId();
var url = 'SPREADSHEET FULL URL'&overlay=false&showEditHistory=true&range=' + row;
// Fetch the HTML content of the Show Edit History feature
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
},
muteHttpExceptions: true
});
if (response.getResponseCode() !== 200) {
Logger.log('There was an error fetching the Show Edit History data.');
return;
}
var html = response.getContentText();
// Extract the editor and timestamp elements
var editorIndex = html.indexOf('Edited by ') + 'Edited by '.length;
var editorEndIndex = html.indexOf('\n', editorIndex);
var editor = html.substring(editorIndex, editorEndIndex).trim();
var timestampIndex = html.indexOf('Timestamp: ') + 'Timestamp: '.length;
var timestampEndIndex = html.indexOf('\n', timestampIndex);
var timestamp = html.substring(timestampIndex, timestampEndIndex).trim();
// Write editor and timestamp to Column A and B of the edited row
sheet.getRange(rowIndex+1, 1).setValue(editor);
sheet.getRange(rowIndex+1, 2).setValue(timestamp);
I really do hope someone can assist in this as I am about to give up and just get users to continue to enter this is manually. (Not ideal but doable)
Thanking all in advance for any feedbackl and or suggestions.