Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
How can i call a variable from one script.gs to another script.gs in app script

In here I am trying to pass/get a variable from Code.gs to NewFile.gs. I would like to pass a folderIdwhich i get it from input box and use it in different file gs instead of inserting manually.

Here is the code:

Code.gs

 if (userInput == "yes") {

var folderId = Browser.inputBox('Enter folder ID', Browser.Buttons.OK_CANCEL);  
}

var parent = DriveApp.getFolderById(folderId);                            
var parentName = DriveApp.getFolderById(folderId).getName();

NewFile.gs

function newFileUpdate() {

var parent = DriveApp.getFolderById("folderId from input box");                            
var parentName = DriveApp.getFolderById("folderId from input box").getName();
                
 getChildFiles(parentName, parent);
 getRootFiles(parentName, parent);
  }

So i would like to know a simple way for me to get the folder id from code.gs into NewFile.gs

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can always pass variables around via function arguments.

Your code.gs can pass the variable you want to newFileUpdate/0 by giving it a function arity of 1, which is to say "Give the function an argument" like...

Code.gs

// add variable
var folderId;

if (userInput == "yes") {    
    folderId = Browser.inputBox('Enter folder ID', Browser.Buttons.OK_CANCEL);  
}

var parent = DriveApp.getFolderById(folderId);                            
var parentName = DriveApp.getFolderById(folderId).getName();

// Send folderId to newFileUpdate/1
newFileUpdate(folderId);

NewFile.gs

// added argument folderId to function
function newFileUpdate(folderId) {
   var parent = DriveApp.getFolderById(folderId);                            
   var parentName = DriveApp.getFolderById(folderId).getName();
                
   getChildFiles(parentName, parent);
   getRootFiles(parentName, parent);
}

edit: Just realized I misunderstood the question and how you structured your code. You're trying to get the folderId down into your NewFile.gs

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda