Create a File, Set Property Values, and Save It to the File Cabinet

The following sample shows how to create and save a file to the File Cabinet. It also shows how to set the values of the File.isOnline and the File.folder properties. 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
    // Note that the folder value is hard-coded in this sample, and you should
    // use a valid folder ID from your account
    let fileObj = file.create({
        name: 'testHelloWorld3.txt',
        fileType: file.Type.PLAINTEXT,
        contents: 'Hello World\nHello World',
        folder: -15,
        isOnline: true
    });
 
    // Save the file
    let id = fileObj.save();
 
    // Load the same file to ensure it was saved correctly
    fileObj = file.load({
        id: id
    });
}); 

        

General Notices