0

I am running into a weird problem where the createFolder function just freezes. I get no error no failure and its just stuck there. I have it running on another sheet with no issue but in this particular project, it gets stuck.

The major difference about this project is that I am using a master sheet to update another sheet when changes occur. I am leveraging variables from the second sheet which I am pulling into the Master sheet. All my connections seem to be in order as far permissions to execute between both sheets. I am the owner of both and I have granted the project the appropriate permissions.

The General code:

var dash = SpreadsheetApp.openById('mysheetid').getSheetByName('config');

//CAPTURE INPUTS
var myName = Browser.inputBox("Enter the Name of the Plan:",Browser.Buttons.OK_CANCEL); 

//GET TARGET FOLDER
var rowUID = gl.findCell(na,myUID); //gl is global variable I am pulling in, na is another sheet record

var parentFolder = GetTargetFolder(dash,"E3");//dash secondary sheet record
var folderName = myUID + "-" + myName;
var nFolderId = createFolder(folderName, parentFolder);
var colUID;

I get stuck here:

function createFolder(FolderName, TargetFolder)
{
 //FolderName is the name of the folder you want to create
 //TargetFolder is the name of the parent folder you need the folder ID to do this.  You need this in order to create folder
 //Newly created folder ID will always be returned as an output.


  var parentfolder = DriveApp.getFolderById(TargetFolder);
  var newFolder = DriveApp.createFolder(FolderName);

  var currentFolders = newFolder.getParents();
  while (currentFolders.hasNext()) 
  {
    var currentFolder = currentFolders.next();
    currentFolder.removeFolder(newFolder);
  }

  parentfolder.addFolder(newFolder);  
  var folderID = newFolder.getId();

  return folderID;

};

Once I declare parentfolder nothing happens. No error, no nothing its just stuck. As mentioned i have this same exact code running in another sheet and it works fine. Anyone have any thoughts?

  • Do you already verified that targetFolder has a valid folder Id and that the script has access to it? How are you calling the script? What do you mean by " I have granted the project the appropriate permissions"? – Rubén Jun 1 '18 at 18:58
1

Folks this is resolved it just started working on its own. I am assuming it was a chrome browser issue since I rebooted and it started working. I can't seem to make the issue happen again which makes me happy but still bothersome that I couldn't find the root cause.

Closing out previous questions:

Do you already verified that targetFolder has a valid folder Id and that the script has access to it? How are you calling the script? What do you mean by " I have granted the project the appropriate permissions"? – Rubén Jun

  1. I had verified the target folder by debugging and grabbing the link provided and manually testing it was there.
  2. The script is being called from a custom menu that just calls the function.
  3. What I meant by granted appropriate permissions was that Google requires permission to run scripts and create folders and documents within your profile. This usually comes in the form of Google prompting you to allow access.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.