Morris S
Morris S

Reputation: 2594

How do I create a folder in the file cabinet in SuiteScript 2

How do I create a new folder in SuiteScript 2.0 and save it to the file cabinet?

var folder = record.create({
    type: record.Type.FOLDER,
});

folder.save()    

What am I missing?

Upvotes: 4

Views: 3342

Answers (2)

Maria Berinde-Tampanariu
Maria Berinde-Tampanariu

Reputation: 1041

Here's a snippet which creates a folder using SS2.0:

        var objRecord = record.create({
            type: record.Type.FOLDER,
            isDynamic: true
        });
        objRecord.setValue({
            fieldId: 'name',
            value: 'Test Folder'
        });
        var folderId = objRecord.save({
            enableSourcing: true,
            ignoreMandatoryFields: true
        });

Upvotes: 11

Charl
Charl

Reputation: 812

This is what I use to save a file to a specified folder:

var exportFolder = runtime.getCurrentScript().getParameter({name: 'custscript_export_folder'});
var fileObj = file.create({ 
        name: scriptContext.newRecord.id + '.json',
        fileType: file.Type.JSON,
        contents: recordAsJSON, description: 'Products sent to warehouse', encoding: file.Encoding.UTF8,
        folder: exportFolder,
        isOnline: false 
        });
    var fileId = fileObj.save();

If the specified folder does not exist, it will be created. In my example, I pass the folder name as a parameter. This is simply specified as "Folder1/folder2". If folder1 exists and folder2 does not, folder2 will be created in folder1.

Upvotes: 2

Related Questions