Script for GoogleSheets that inserts date, time, and user names of everyone entering text in a specified cell?

by µHg30   Last Updated February 17, 2018 22:03 PM

I wanted to ask for your help in building a script in Google spreadsheet that would allow users to respond to comments left by different users in the same cell (cell where the initial comment was originally posted), while having this script insert a [date, time, user name] stamp in the beginning of currently written comment. Visually the end result of that one cell would ideally look like this:

[12/07/17, 11:15am, John] has this project been submitted? 
[12/07/17, 11:19am, Steve] currently finalizing it. Will be ready in 10 minutes 
[12/07/17, 11:22am, John] thanks for the update.

A script is currently floating around which is similar, but it is very limited - a slightly edited version is in the linked spreadsheet. This spreadsheet also contains a visual example and an explanation of what I'm trying to achieve. Please take a look and let me know if any further clarification is needed.

https://docs.google.com/spreadsheets/d/1tzVifer8KUNNoTXKq2W_-CCGzpD7EzIetTW5w_3EoSc/edit?usp=sharing

function onOpen() {
    SpreadsheetApp.getUi().createMenu('Allow Script?')
        .addItem('Yes', 'createSpreadsheetEditTrigger')
        .addToUi()
}

function createSpreadsheetEditTrigger() {
    checkTriggers();
    ScriptApp.newTrigger('runOnEdit')
        .forSpreadsheet(SpreadsheetApp.getActive())
        .onEdit()
        .create();
    var user = Session.getActiveUser().getEmail();
    SpreadsheetApp.getUi().alert('script is now authorized by ' + user + '');
}

function runOnEdit(e) {
    if (e.source.getActiveSheet().getName() !== 'Sheet1' || e.range.columnStart !== 1 || !e.value) return;
    e.range.offset(0, 1, 1, 2).setValues([
        [Session.getActiveUser().getEmail().split("@")[0],new Date()]
    ]);
}

function checkTriggers() {
    var allTriggers = ScriptApp.getProjectTriggers();
    if (allTriggers.length > 0) {
        for (var i = 0; i < allTriggers.length; i++) {
            ScriptApp.deleteTrigger(allTriggers[i]);
        }
    }
}


Related Questions


How to format the time in this Google Docs script

Updated July 12, 2018 14:03 PM

How to Process Rows of Google Sheet Singly?

Updated April 05, 2018 19:03 PM

auto timestamps for multiple column separately

Updated March 25, 2018 11:03 AM