Apps Script code used to run before but not anymore

Viewed 19

So I had this code which used to take names of people as a list in google sheets, extract the pdf with the same name from a folder in google drive and make a new folder with the provided name in the sheet. Since late, an error shows up saying Insufficient data, which is what it is supposed to show if the column is empty. However, even with data in the column, the error shows up.

const srcFolder = "Folder Name in the drive (same as before)";
const workbookID = "google sheet workbook id(same)";
const sheetName = "MainSheet";

function resumeSorter() {
  let resumeList = SpreadsheetApp.openById(workbookID).getSheetByName(sheetName);  //getting consent list
  const destinationFolderName = resumeList.getRange(1, 2).getValue();   // where the resumes will be sent

  let numConsents = resumeList.getRange(2, 2).getValue();  // no. of consents
  if (numConsents > 0 && destinationFolderName != '') {
    numConsents = numConsents + 5;  // additional rows added

    let dApp = DriveApp;
    let folders = dApp.getFoldersByName(srcFolder); //Folder where all the resumes have been stored
    let unStampedFolder = folders.next();

    let fileIterator = unStampedFolder.getFiles();

    let requiredFileName;
    let counter;

    let destinationFolder = dApp.createFolder(destinationFolderName);
    destinationFolder = dApp.getFoldersByName(destinationFolderName);
    destinationFolder = destinationFolder.next();


    while (fileIterator.hasNext()) {
      let resumeFile = fileIterator.next();        // resume
      let resumeFileName = resumeFile.getName();   // name of the resume file from the consent sheet

      counter = 5;                                 // increment rows

      while (counter <= numConsents) {
        requiredFileName = resumeList.getRange(counter, 1).getValue();
        requiredFileName = requiredFileName + ".pdf";

        if (requiredFileName == "") {
          Logger.log("Complete");
          return;
        }
        else if (resumeFileName == requiredFileName) {
          resumeFile.makeCopy(destinationFolder);
          resumeList.getRange(counter, 3).setValue("Transfered");
          break;
        }
        else {
          counter++;
        }
      }
    }

    resumeList.getRange(4, 1).setValue("Transfer Complete");
    resumeList.getRange(4, 1).setBackground('#00ff00');
    resumeList.getRange(4, 1).setFontColor('#000000');
  }
  else {
    if (!(numConsents > 0) && (destinationFolderName == '')) {
      resumeList.getRange(1, 2).setValue("Enter Name Here...");
      resumeList.getRange(6, 1).setValue("Paste Consent List Here...");
      resumeList.getRange(1, 2).setFontColor('red');
      resumeList.getRange(6, 1).setFontColor('red');
    }
    else if (!(numConsents > 0) && (destinationFolderName != '')) {
      resumeList.getRange(6, 1).setValue("Paste Consent List Here...");
      resumeList.getRange(6, 1).setFontColor('red');
    }
    else if ((numConsents > 0) && (destinationFolderName == '')) {
      resumeList.getRange(1, 2).setValue("Enter Name Here...");
      resumeList.getRange(1, 2).setFontColor('red');
    }
    resumeList.getRange(4, 1).setValue("Insufficient Data");
    resumeList.getRange(4, 1).setBackground('#ff0000');
    resumeList.getRange(4, 1).setFontColor('#ffffff');
  }
}
0 Answers
Related