0
votes

I have prepared a format in google spreadsheet which takes inputs/updates from several users. Sometimes three or four users might be accessing the same sheet at a point of time for updating the format in the sheet.

the Issue is: An Error raises ("oops... ") when my onEdit function fires for date/time stamp on editing a row in sheet. Majority of timestamp is not inserted when this error is displayed.

this might be a a frequent edits done on several rows at the same time. Can any one direct me how to over come this issue; Is there any option or alternative for row based timestamp/Date without onedit function;

the following is the script i have been used for date/time stamp correct me if there is an error in my script mentioned below.

function onEdit(){

 var s = SpreadsheetApp.getActiveSheet();  

 var sheetname = SpreadsheetApp.getActiveSheet().getName()

 var s = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Footfall-Format');

if(s.getName() == 'Footfall-Format' ) { //checks that we're on the correct sheet

var totrows = s.getMaxRows();

var r = s.getActiveCell();

if( r.getColumn() >= 2 &&  r.getColumn() <= 15) { //checks the column

// in order to conver -ve to +ve 

if(r.getColumn() < 0){

r.getColumn() = r.getColumn() * -1;

} 

//diffrence of colums makes a standar col

var settimsmp = 16 - r.getColumn();

//cahnge negetive num,ber to +ve then caculate row number;

var nextCell = r.offset(0, settimsmp);

if( nextCell.getValue() === '' ) //is empty?

var stringdate = new Date();

time = Utilities.formatDate(new Date(stringdate), "GMT", "dd-MMM-yyyy");   

nextCell.setValue(time);

SpreadsheetApp.flush(); //force the data to be written            

};

};

SpreadsheetApp.flush(); //force the data to be written

}
1

1 Answers

1
votes

This is a common "critical section" problem, and Google Apps Script provides a Lock Service to address it.

Take a look at this answer for an example of a function utilizing this technique.