Deleting a Folder From the File Cabinet Using a Script

Hello,

I’ve been trying to figure this out for a while now. I can use a script to delete files from the cabinet based off of a saved search used within the script, but I’ve looked almost everywhere and I can’t find a way to delete an entire folder.

It looks like the folder is a record, but I can’t seem to make it work. I’ll include some examples of the file script vs the folder script that I have right now.

More so, it’s actually any folders within a parent folder that I’m trying to Delete. I’ve managed to create the search that shows the subfolders using:

 

Criteria

Sub of is “Parent Folder”

Last Modified: On or before

 

Results:

Name

Internal ID

 

File Script Example (working for deleting all files within a folder based on the saved search):

function deleteFiles(request, response)

{

var s = nlapiSearchRecord(‘file’, ‘customsearch_whatever’);

for (var i = 0; i < s.length; i++) {

var cols = s[i].getAllColumns();

var internalId = s[i].getValue(cols[0]);

var fileName = s[i].getValue(cols[1]);

var type = s[i].getValue(cols[2]);

var size = s[i].getValue(cols[3]);

var dateCreated = s[i].getValue(cols[4]);

var lastModified = s[i].getValue(cols[5]);

nlapiDeleteFile( internalId );

 

Folder Script Example (not working. Execution Log has is blank for details):

function deleteFolder(request, response)

{

var s = nlapiSearchRecord(‘folder’, ‘customsearch_whatever’);

for (var i = 0; i < s.length; i++) {

var cols = s[i].getAllColumns();

var internalId = s[i].getValue(cols[0]);

var folderName = s[i].getValue(cols[1]);

var type = s[i].getValue(cols[2]);

var size = s[i].getValue(cols[3]);

var dateCreated = s[i].getValue(cols[4]);

var lastModified = s[i].getValue(cols[5]);

//nlapiDeleteSubsidiary( internalId );

nlapiDeleteRecord(‘folder’, internalId);

}

}

I know I’m using a record to try to delete the folder in the second script example, but I tried many other avenues and that was a last ditch effort to try to figure it out.

Any help or information on this would be greatly appreciated. Thank you!

Rookie Asked on September 4, 2022 in Administration.
Add Comment
1 Answer(s)

I can confirm that nlapiDeleteRecord works for a folder so it must be something to do with the saved search / rest of your logic.

Are you able to add some additional logging and share the resuklts?

Intermediate Answered on September 5, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor