1
votes

I have two functions created in the same script and I would like the secondary to activate the main function if cell "N1" on the "Main Stage" page were written "Ok".


function CallFunction() {
  var spreadsheet = SpreadsheetApp.getActive();

  var ss=SpreadsheetApp.getActive();
  var sh=ss.getSheetByName('Main Stage');
  var rg=sh.getRange("N1");
  var vA=rg.getValues();
  if (vA[0][0]=="Ok"){

  spreadsheet.getRange('Activate!A1').activate();
  spreadsheet.getCurrentCell().setFormula('=MainFunction()');
}

At the moment when trying to activate, it appears in the spreadsheet → You do not have the permission required to setValue (Line 10). From what I saw, I cannot activate my function directly from a spreadsheet cell.

How could I solve this problem?

1
If the error occurs when =MainFunction() is put to a cell, unfortunately, the custom function cannot use setValue(). It is required to use other method and/or workaround. So can you provide =MainFunction()?Tanaike
@Tanaike Is there any way to activate the Function MainFunction() directly on script instead of typing it through the spreadsheet?Brondby IF
Thank you for replying. Although I'm not sure whether I could correctly understand about active of your replying, when you want to run the function of MainFunction(), for example, how about modifying spreadsheet.getCurrentCell().setFormula('=MainFunction()'); to MainFunction()?Tanaike
@Tanaike I can't believe it was that simple. Thank you, I had not really stopped to imagine that simply writing the function could be activated. I thank you so much, I'm sorry I took your time for something so simple. I hope I didn't disturb you.Brondby IF
@Tanaike I can't mark your comment as the comment that solved the problem. I'd like to mark you as the case solver but it's not working. I only had to mark that your comment was helpful.Brondby IF

1 Answers

2
votes

When you want to run the function of MainFunction() in the function of CallFunction(), please modify as follows. By this, MainFunction() can be run.

From:

spreadsheet.getCurrentCell().setFormula('=MainFunction()');

To:

MainFunction();

Note:

  • When =MainFunction() is used, unfortunately, setValue() cannot be used for the custom function.