ANS-1197 · SUITESCRIPT DEVELOPMENT
How to Automate File Cabinet Folder Downloads in NetSuite?
Implement a client-side script to automate the download of all files from a NetSuite File Cabinet folder as a single ZIP archive.
Short answer
Automate NetSuite File Cabinet folder downloads using a client-side script that redirects to a specific URL: '/core/media/downloadfolder.nl?id={folderid}'. This method dynamically constructs the correct environment-specific URL, triggering the download of all folder contents as a ZIP file, mirroring NetSuite's native download functionality.
Scenario
Users often require a streamlined method to download multiple files from a NetSuite File Cabinet folder simultaneously, rather than downloading each file individually. This need arises when consolidating documents, archiving data, or performing bulk operations that benefit from a single, automated download action.
Solution
The solution involves implementing a client-side script that programmatically triggers the download of a specified File Cabinet folder's contents. This is achieved by constructing and navigating to a specific NetSuite internal URL, which initiates the download of all files within the folder as a ZIP archive. The core of this functionality relies on the URL structure: '/core/media/downloadfolder.nl?id{folderid}'. This URL is the same one NetSuite uses internally when a user manually clicks the 'Download' button within the File Cabinet. To implement this, a 'Download' button can be added in view mode, triggering the following client-side function:
javascript
var DOWNLOAD_URL '/core/media/downloadfolder.nl?id{folderid}';
var SANDBOX_ENVIRONMENT 'SANDBOX';
var SANDBOX_BASE_URL 'https://system.sandbox.netsuite.com';
var PRODUCTION_BASE_URL 'https://system.netsuite.com';
function downloadFiles(folder){
if (folder ! null && folder ! '') {
var environment nlapiGetContext().getEnvironment();
var url '';
var downloadUrl DOWNLOAD_URL.replace('{folderid}', folder);
if (environment SANDBOX_ENVIRONMENT) {
url SANDBOX_BASE_URL + downloadUrl;
} else {
url PRODUCTION_BASE_URL + downloadUrl;
}
window.location url;
}
}This function dynamically determines the current NetSuite environment (Sandbox or Production) and constructs the appropriate base URL. It then appends the downloadUrl, replacing {folderid} with the actual ID of the target folder. Finally, window.location = url; redirects the browser, initiating the download of the ZIP file containing all contents of the specified folder.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
