Rob
09/11/2024, 10:25 PMCeligo AI
09/11/2024, 10:25 PMAI generated answer (using internal Slack threads):Yes, it is possible to prevent files with the same name from being uploaded and overwritten via script in NetSuite. However, this would require some additional logic in your script to check if a file with the same name already exists in the target folder before attempting to upload a new file. Here is a sample code snippet that demonstrates this:
javascript
var fileType = file.Type.PLAINTEXT;
var folder = <FOLDER ID>;
var name = 'test.txt';
// Search for existing file with the same name in the target folder
var filters = [
search.createFilter({
name: 'name',
operator: <http://search.Operator.IS|search.Operator.IS>,
values: [name]
}),
search.createFilter({
name: 'folder',
operator: search.Operator.ANYOF,
values: [folder]
})
];
var searchResult = search.create({
type: 'file',
filters: filters
}).run().getRange({start: 0, end: 1});
// If no existing file is found, create a new file
if (searchResult.length === 0) {
file.create({ fileType: fileType, folder: folder, name: name, contents: 'First' }).save();
}
This script first performs a search in the file cabinet to check if a file with the same name already exists in the target folder. If no such file is found, it proceeds to create and save a new file. If a file with the same name already exists, the script does nothing, effectively preventing the existing file from being overwritten.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
09/11/2024, 10:26 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.798085213
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.794435143
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.789945602
Celigo AI
09/11/2024, 10:26 PM