I have a script in a google spreadsheet that works perfectly but only with my user, when another user does the action that executes the script, it does not work even if the user gives it permission in his account, any solution?
I leave a link to the example of the spreadsheet that I mention:
https://docs.google.com/spreadsheets/d/1y5H1x84tyt43HEhtescDmuL-cXPHhL8KzJ2MkT_3eZo/edit?usp=sharing
I leave an example of the code here:
function onEdit(e){
var curDate = Utilities.formatDate(new Date(), "GMT+01:00", "hh:mm");
var range = e.range;
var colIndex = range.getColumnIndex(); //Same as getColumn()
var rowIndex = range.getRowIndex(); //Same as getRow()
var DateCol1 = "K9"; //Cell you want to have the date
var DateCol2 = "U9";
if(e.range.getSheet().getName() === 'PARCMÒBIL'){
var watchRange1 = {
top : 11, // start row
bottom : 109, // end row
left : 3, // start col
right : 11, // end col
};
var watchRange2 = {
top : 11, // start row
bottom : 109, // end row
left : 13, // start col
right : 21, // end col
};
if(colIndex >= watchRange1.left && colIndex <= watchRange1.right &&
rowIndex >= watchRange1.top && rowIndex <= watchRange1.bottom && e.Value
!= 0){
SpreadsheetApp.getActiveSheet().getRange(DateCol1).setValue(curDate);
//Write the date in the cell
}else if (colIndex >= watchRange2.left && colIndex <= watchRange2.right
&& rowIndex >= watchRange2.top && rowIndex <= watchRange2.bottom &&
e.Value !=0){
SpreadsheetApp.getActiveSheet().getRange(DateCol2).setValue(curDate);
};};
}
Your code has at least one error
should be
This is because Google Apps Script is case sensitive. The event object has a property
value
, noValue
.To debug your code and find this and possibly other errors follow the recommendations given in How can I test a trigger function in Google Apps Script
I have found the solution to my problem, and the truth is that it was a very big nonsense, the script was working with the other users, the problem was that the box where the script had to write those users had it protected, when they unprotected that cell the script works perfectly.
Conclusion: The google spreadsheet scripts respect the protections.