0
votes

I created the following onEdit function on Google Scripts to trigger the pullJobIDS function. The pullJobIDS function is working properly but the problem is with the onEdit function. I don't know why is not triggering. Can you see any syntax mistake?

The goal is to run the pullJobIDS function when any value in the Column with index 2 is modified different from NULL and in the Organisational Structure sheet only.

function onEdit(e) {
  if (e.source.getActive().getName() == 'Organisational Structure' && e.range.getColumn() == 2 && e.range.getValue() != "") { pullJobIDS() }
 }

I would appreciate any help with this. Thanks

1
Well, does pulJobIds meet all the same restrictions that apply to simple trigger functions? If not, then of course it cannot run when it is activated by a simple trigger. You don't provide any idea of what that code does, so we can only assume it requires permissions that it does not have when executed as a simple trigger. Also note that e.source is a Spreadsheet, not a Sheet - use either e.range.getParent().getName() or e.source.getActiveSheet().getName() instead. - tehhowch
Thank you so much for your help. Now it's working. I just removed e.range.getValue() != "" because it was giving me problems. So the final code is: function onEdit(e) { if (e.source.getActiveSheet().getName() == 'Organisational Structure' && e.range.getColumn() == 2) { pullJobIDS() } } and I set up an OnEdit trigger to trigger this onEdit function. Thanks a lot! - Marco
Welcome. Thank you for letting me know. If your question was solved, please push an accept button. Other people who have the same issue with you can also base your question as a question which can be solved. If you don't find the button, feel free to tell me. stackoverflow.com/help/accepted-answer - Tanaike

1 Answers

1
votes

The reason is that your script occurs an error at e.source.getActive().getName(). You can see the error by Execution transcript. In order to remove this error, please modify as follows.

From :

e.source.getActive().getName()

To :

e.source.getActiveSheet().getName()

Note :

  • In this modification, when column 2 in the sheet with the sheet name of 'Organisational Structure' is edited, if the edited cell is not empty, pullJobIDS() is run.
  • For your script, if some methods which are required to authorize are included in pullJobIDS(), please use the installable trigger.

Reference :

If I misunderstand your question, I'm sorry.