D
D
demarin2021-01-15 00:08:05
Google Apps Script
demarin, 2021-01-15 00:08:05

Why doesn't google script work when I log in from another device?

function onEdit(e)
{
  var range = e.range
  if(range.getColumn()==1 && e.value!=null){
    range.offset(0,1).setValue(new Date())
  }
}


There is a function that automatically enters data into the second column if you enter something into the first. It works for me in google spreadsheet. I shared a link to this google spreadsheet, and when someone else enters data in the first column, the script for some reason does not work and does not automatically fill in anything. What's wrong here?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
aminodovborisov, 2021-01-15
@aminodovborisov

And the input to the onEdit function at the program level is carried out? Add a line to onEdit and see what happens when another person edits the table. It is also possible that you did not specify the necessary user rights during deployment.
console.log('Что-то там');

M
Maxim Stoyanov, 2021-01-15
@stomaks

The simple onEdit trigger has a number of limitations . Check if you fall under them.
Unlikely, but you can also try adding this code to force the authorization scope to only access the current spreadsheet, and not all spreadsheets:

/**
 * @OnlyCurrentDoc
 */

If you have some other code besides this code that requires authorization. It is necessary to give users the opportunity to log in.
---
Maxim Stoyanov (stomaks), developer of Google Apps Script .
g-apps-script.com
stomaks.me

D
demarin, 2021-01-22
@demarin

Thank you all for your help. The reason why the script didn't work was because the second column, which should have been filled in automatically, was protected from changes. When I granted access, everything worked.
But now I have another question, is it possible to do this so that the column is protected from changes by users, but the data is entered according to the script automatically when the first column is filled in? This is necessary so that other users do not violate anything or accidentally delete the data that it automatically adds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question