Create and Save a File to the File Cabinet

The following sample shows how to create and save a file to the File Cabinet. In this sample, the folder ID value is hard-coded. For the script to run in the SuiteScript Debugger, you must replace this hard-coded value with a valid folder ID from your account.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

Important:

This sample uses SuiteScript 2.1. For more information, see SuiteScript 2.1.

          /**
 * @NApiVersion 2.1
 */
require(['N/file'], file => {
    // Create a file containing text
    let fileObj = file.create({
        name: 'testHelloWorld.txt',
        fileType: file.Type.PLAINTEXT,
        contents: 'Hello World\nHello World'
    });
 
    // Set the folder for the file
    // Note that this value is hard-coded in this sample, and you should use
    // a valid folder ID from your account
    fileObj.folder = -15;
 
    // Save the file
    let id = fileObj.save();
 
    // Load the same file to ensure it was saved correctly
    fileObj = file.load({
        id: id
    });
}); 

        

General Notices