How to Overwrite a File in the File Cabinet Using SuiteScript 2.0

This article will help you overwrite an existing file with the same name in the file cabinet using SuiteScript 2.0.

1. Create and upload a scheduled script:

Save the below code as .js file:

function execute(scriptContext) {

  var fileId = ‘9505’; //file ID

  var fileObj = file.load({

    id: fileId

  });

  var fileType = fileObj.fileType;

  var fileName = fileObj.name;

  var fileContents = fileObj.getContents();

  var fileObjSave = file.create({

    name: fileName,

    fileType: fileType,

    contents: fileContents,

    folder: 962, //folder ID

  });

  var fileId = fileObjSave.save();

Go to Customization > Scripting > Scripts > New

Click the “+” icon beside the Script File select field

On the File pop-up window, click Choose File 

Locate your saved file and select it > click the Save 

On the “Upload Script File” page, click Create Script Record 

On the “Script” page, put a script name on the Name field

Click Save 

2. Deploy the script

On the “Script” page, click the Deploy Script 

On the “Script Deployment” page:

Enter the title on the Title field

Set the Status to Not Scheduled

Click Save.

3. Execute the script

On the “Script Deployment” page, click Edit.

Hover the mouse on the arrow down icon beside the Save button > choose Save and Execute

Leave a comment

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