-1

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.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Sergii Artele
  • 63
  • 1
  • 11

1 Answers1

2

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.

JPV
  • 26,499
  • 4
  • 33
  • 48
  • Thanks. The showModalDialog appears when an array filled by calculations triggered by onEdit(e) has more that one cell. In That dialogue, a user can choose one using radio buttons. So following your advice, should I create a function that will check the length of an array? As a workaround, I think I will do ss.getRange(y, x, 1, array.length).setValues(array); and then an installable trigger should check whether an array size should trigger a modal dialogue. What do you think? Or is there a better way to do it? – Sergii Artele Dec 03 '18 at 08:23
  • Is it the onEdit(e) that does the calculations and then writes to the sheet? Or do you use formulas for the calculation? – JPV Dec 03 '18 at 09:14
  • OnEdit(e) gets data from a user and analyses it whether a modal dialogue should be shown or the rows should be inserted and set formulas into added rows. I am just trying to get an idea how to make my new installed trigger to obtain values of an array that generated by onEdit – Sergii Artele Dec 03 '18 at 10:00