Reputation: 11
My code use to work well but since a couple of weeks Im having trouble.
First I defined the mooveFile function:
function mooveFile(file,folder,source,copyNameFile){
var newfile = file.makeCopy(copyNameFile, folder);
source.removeFile(file);
Logger.log(source.getFiles().length);
return newfile.getUrl();
}
Then Im calling the function later in my script:
if (statutFile=="Validé") {
var fichiersj=folderSource.getFilesByName(libeleFile);
while (fichiers.hasNext()) {
var fichiersj = fichiers.next();}
var urlFichierVal = mooveFilde(fichiersj,folderValid,folderSource,nomFichier);
sheetform.getRange(i+1,23).setValue("Deplacé");
if (typeFichier == "DEVIS") {
sheetform.getRange(i+1,34).setValue(urlFichierVal);}
if (etatLien !="Lien modifiée") {
var urlFichierValide = urlFichierVal;
var hyp = '"'+urlFichierValide+'"';
var argHyp = ";";
var sepHyp = '"';
var hrefHyp = "=HYPERLINK("+hyp+argHyp+sepHyp+"Accèder au "+typeFichier+" Validé"+'")';
sheetform.getRange(i+1,18).setValue("Lien modifiée");
sheetform.getRange(i+1,6).setValue(hrefHyp);
}
}
The error I got is:
TypeError: Impossible to call the "makeCopy" method from undefined.
It seems to me that the problem come from the:
while (fichiers.hasNext()) {
var fichiersj = fichiers.next();}
However I don't know how it became undefined. It uses to work well!
Upvotes: 0
Views: 163
Reputation: 7377
Looks like you have an extra } in your code, on the line:
var fichiersj = fichiers.next();}
This is ending the While loop after that line, instead of executing the rest of you code.
Once the while loop finishes, "fichiersj" is undefined, since it was only defined within your loop.
Upvotes: 1