file.copy(options)

Note:

The content in this help topic pertains to SuiteScript 2.0.

Method Description

Copy an existing file in the NetSuite File Cabinet.

When you copy a file using this method, the copied file has the same properties as the original file. For example, if the original file is available without login, the copied file is also available without login.

You can use the file.NameConflictResolution enum to specify how to resolve conflicts when copying files. A conflict occurs when the target folder for a copy operation already contains a file with the same name as the file to copy. When a conflict occurs, you can specify how the conflict is resolved. For example, you can specify that the copy operation should fail if a conflict occurs.

Returns

file.File

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

20 units

Module

N/file Module

Since

2021.1

Parameters
Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

Since

options.folder

number

required

The internal ID of the folder to copy the file to.

This folder must already exist in the File Cabinet.

2021.1

options.id

number

required

The internal ID of the file to copy.

This file must already exist in the File Cabinet.

2021.1

options.conflictResolution

string

optional

The conflict resolution value.

This parameter specifies the type of conflict resolution to apply when a conflict occurs while copying a file (for example, if the target folder already contains a file with the same name). Use the values in the file.NameConflictResolution enum to set this parameter.

The default value is ConflictResolution.FAIL.

2021.1

Errors

Error Code

Thrown If

INVALID_CONFLICT_RESOLUTION_1

A value is specified for the options.conflictResolution parameter that is not from the file.NameConflictResolution enum.

SSS_MISSING_REQD_ARGUMENT

A required argument is not passed.

Syntax
Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/file Module Script Samples.

          // Add additional code 
...
var fileObj = file.create({
    name: 'test.txt',
    fileType: file.Type.PLAINTEXT,
    contents: 'Hello World\nHello World'
});
fileObj.folder = -15;
var id = fileObj.save();

fileObj = file.copy({
    id: id,
    folder: -4,
    conflictResolution: file.ConflictResolution.FAIL
});
...
 // Add additional code 

        

Related Topics

N/file Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices