Ben Barsocchini
Ben Barsocchini

Reputation: 9

TypeError: Cannot find function getId in object

I'm working on a project where I'm trying to get a sheet to autoupdate with info from a new sheet every day. The new sheet will be dropped in the same folder and will be given the same name every day. However, I need to get the new sheet key every day to make the code run with the new sheet importing data.

I experienced a type error in my searchfolder function that told me it couldn't find the function getId in the object "Daily" (my source sheet). If anyone could tell me my mistake or suggest a better way to get, store and then apply the key id in line 31 that would be great!

var counter = 0;

var files = [];

function searchFolder() {
  var folderId = '0B6wmHZ5c0fzfTjI1bFpKOHI3N3M'; // test folder
  // Log the name of every file in the folder.
  var filesN = DriveApp.getFolderById(folderId).getFiles(); //log files in folder
  while (filesN.hasNext()) 
    files.push(filesN.next().getName().getId());
}

function autoUpdate() { //updates monthly from newly imported daily
  if (counter == 1) { //counter is made to be 1 when day is uploaded to monthly
    var ss = SpreadsheetApp.openById("1lH9Y12P2Q2OFndIJoAU48ePggXFc9WGcWjolZMcABoc");
    //defines target spreadsheet ie monthly
    SpreadsheetApp.setActiveSpreadsheet(ss); //sets target spreadsheet as  
    active
    var range = ss.getRange("A1:A1"); //sets range in target. ONLY CHOOSE ONE 
    CELL FOR IMPORTRANGE - IF MORE THAN 1 IS CHOSEN YOU WILL GET A# REF
    ERROR BECAUSE IT WILL PUT IMPORTRANGE IN ALL CELLS
    range.activate; // activates range
    range.setValue('=IMPORTRANGE("1hVv6ldHEaCCI_uptr0MpzAyP60x7on8YR_brWwWXTWo","she   et1!A1:167")');
    counter = (counter - 1)
  }
}

function timeStamp() {
  if (files == "Daily") {
    counter = (counter + 1)
  }
}

searchFolder();
timeStamp();
autoUpdate();

Upvotes: 0

Views: 1950

Answers (1)

joews
joews

Reputation: 30330

You are calling filesN.next().getName().getId().

filesN.next() returns a File object, but File#getName returns a String.

The right function is File#getId:

while (filesN.hasNext()) 
    files.push(filesN.next().getId());

Upvotes: 1

Related Questions