Tuesday, June 4, 2019

Mass Delete Files using SuiteScript

This article provides an example on how to mass delete files created over x days ago.

The concept to get this done is by creating a Document Saved Search in the UI and pull down the results via SuiteScript.  Basic knowledge in SuiteScript and searches is required for the instructions below.

     1. Create a Document Search in the UI (Lists > Search > Saved Searches > New > Document)
          1.a Title = Any
          1.b ID = _jdocument (For SuiteScript use)

     2. Criteria: Date Created is within 3/1/2011 and 3/1/2011

     3. Under Results tab, I added the following:
           3.a Internal ID
           3.b Name
           3.c Type
           3.d Size (KB)
           3.e Date Created
           3.f Last Modified

     4. Finally, the script pulls up the above search:

          var s = nlapiSearchRecord('file', 'customsearch_jdocument');

          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 );

This can be used as temporary workaround since Files are not yet officially supported in SuiteScript.

The functionality is being tracked under Enhancement# 135472 (SuiteScript - Add methods to add and update files in the File Cabinet).


DISCLAIMER: The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Netsuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.

Netsuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Netsuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.

Netsuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.

No comments:

Post a Comment