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. 

/**@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
});
});

Leave a comment

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