1

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?

6
  • 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()? Commented Aug 23, 2019 at 23:21
  • @Tanaike Is there any way to activate the Function MainFunction() directly on script instead of typing it through the spreadsheet? Commented Aug 23, 2019 at 23:26
  • 1
    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()? Commented Aug 23, 2019 at 23:29
  • 1
    @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. Commented Aug 23, 2019 at 23:43
  • 1
    @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. Commented Aug 23, 2019 at 23:44

1 Answer 1

2

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.