google-apps-scriptgoogle-sheetstriggersshowmodaldialog

enabled trigger onEdit launches functions twice, not enabled stops modal dialog to show up


I have an Apps Script with onEdit(e) function. That function calls some other functions depending on existing and new data. In certain cases, showModalDialog needs to be shown. If I enable function onEdit(e) via trigger onEdit, it launches some function twice (like inserting rows and performing calculations). If I delete that trigger from a trigger list, then showModalDialog cannot be shown and error You do not have permission to call showModalDialog at showDialog(Code:82) at onEdit(Code:1270)

The idea is to make showModalDialog to appear when required and start all other function only once when a user edits data. I would really appreciate if you help me with a solution.


Solution

  • A function called onEdit(e) is already a trigger on its own: this is called a simple trigger. To show the showModalDialog you will need to create an installable trigger. If you do that on the function onEdit you'll probably end up with two triggers (one simple, one installed) for the same function. IMO, It would be better to rename the function and then use an installable (onEdit) trigger on that function.