Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

Get NetSuite List of Files From Folder

NetSuite Technical

Tags: , , , , ,

This article is relevant if you are want to dynamically create a list of file names for user selection. It also helps explain concepts on complex search columns lookups.

Background

Reviewing NetSuite’s Record Browser, you may notice that a “File” object is not available. That is because it is really not a “record”. You use NetSuite’s nlapiLoadFile(id) function to load a file versus nlapiLoadRecord syntax.

However, you may have a list of files that you want to present to the user for some type of operation. Suppose that you have designated a particular folder in the NetSuite File Cabinet to hold some special files. How do you get a list of those files?

SuiteScript Solution for Filename Dropdown List

The following code snippet can be plugged into a UserEvent BeforeLoad function to help draw a file dropdown list. The key here is to perform a search on the Folder record object. All files have a parent folder ID. We basically are going to use the join functionality of a saved search to get to the files in the folder.

// pass in the internal id of the file's parent folder
var folder = 415 // the folder ID we care about

var filters = new Array();
filters[0] = new nlobjSearchFilter('internalid', null, 'is', folder);

// get two columns so we can build a drop down list: file name and file internal ID
var columns = new Array();
var filename = new nlobjSearchColumn('name', 'file');
var fileid = new nlobjSearchColumn('internalid', 'file');

//use this syntax so we can pass in the object reference to get the file info, not the
//text representation of column lookup
columns[0] = filename;
columns[1] = fileid;

// perform the search and loop through the findings
var searchResult = nlapiSearchRecord('folder', null , filters , columns);
if(searchResult) {
	for (var i = 0 ; i < searchResult.length; i++) {
		var f = searchResult[i];
		//add values to the "template" dropdown field created earlier in the UI
		//leveraging our getValue(<object reference>) syntax
		template.addSelectOption(f.getValue(fileid), f.getValue(filename));
	};
};

A Word About Search Column References

The typical way to reference columns from a search is to enter something like getValue(‘internalid’). NetSuite’s sample code shows syntax like this all the time. This technique works if the column is not complex. But in our case, we are referencing joined columns which is less simple. The same thing can happen if you create complex formula columns.

What you need to do is reference the explicit column definition through a variable pointer to your column array elements. See comments in the code snippet.

Get Help

NetSuite was designed to be extended to meet unique business requirements. In the hands of the right actors, you can expand your capacity to automate business process, increase revenue and lower costs. Contact us if you would like to get more from your NetSuite investment.

Marty Zigman LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

BiographyYouTubeLinkedInX (Twitter)

15 thoughts on “Get NetSuite List of Files From Folder

  1. Hi Marty,

    Is it possible to retrieve a file on an external suitelet post without using the NetSuite form.addField?

    In other words, I want to use a simple and retrieve that file on form post using request.getFile.

    Reply
  2. Sorry, looks like some of my previous post didn’t go through. Here’s the edited version:

    Is it possible to retrieve a file on an external suitelet post without using the NetSuite form.addField?

    In other words, I want to use a simple “input type=file” and retrieve that file on form post using request.getFile.

    Reply
  3. Marty, I’m making a custom “app” via external suitelets and part of the functionality is to allow the user to submit files. The UI for this app is 100% custom, and so I can’t use the NetSuite form.addField anything because there’s no way to put these fields exactly where I want them on the page (unless I’m wrong about this?). As such, I use my own fields using standard HTML inputs and, in some cases, DIVs. The only exception is the file field. On the post action of the form, NetSuite will not return any object from a standard input type=file – it has to be a form.addField input. Because of this I have to create a separate suitelet just to handle the file upload, which is annoying and doesn’t look good due to lack of design control. Hence, I’m still wondering if I can somehow grab the file on the post action from a standard HTML input…..

    Reply
  4. Hi Marty, is it possible to get the pdf file from filecabinet going to newly created custom body field in invoice using SuiteScript? can you guide me how to do that.? thanks.

    Reply
  5. Hi Marty,

    Is this possible to create this in SuiteScript 2.0 Restlet?

    Nothing is returned when modifying the example to work in SuiteScript 2.0 running it in a restlet.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *