0

Okay, I've been a coding for a little while and have had the chance to do a number of things.

One issue I'd like to find a more elegant way is running scripts based on the value of a variable.

At the moment I'm doing it like this.

    if (ScriptName == 'overnightRun' ) {
      overnightRun();
    } 
    if (ScriptName == 'resetAnalysisSheets' ) {
      resetAnalysisSheets();
    } 
    if (ScriptName == 'resetActiveSheetFormulae' ) {
      resetActiveSheetFormulae();
    } 
    if (ScriptName == 'saveRemainingContractSheets' ) {
      saveRemainingContractSheets();
    } 
    if (ScriptName == 'saveAllContractSheets' ) {
      saveAllContractSheets();
    } 
    if (ScriptName == 'saveCurrentContractSheet' ) {
      saveCurrentContractSheet();
    } 
    if (ScriptName == 'clearDataSheets' ) {
      clearDataSheets();
    } 

Surely there must be a better way. Something more like this.

    run.script(ScriptName);

Anyone any ideas? Thanks for reading!

1 Answer 1

2

You could try this:

function testFunction() {
  var ScriptName = "Alibaba";
  var p = "Open sesame!"
  this[ScriptName](p);
}

function Alibaba(p) {
  Logger.log(p);
}

Leave the parameter p blank if nothing is to be passed.

Sign up to request clarification or add additional context in comments.

2 Comments

Super! You may want to accept the anwer
Thanks, I've just done that. Working out my way around Stack Overflow as well ;-)

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.