I have a Suitelet where a user can submit a file. ...
# ask-stanley-ai
s
I have a Suitelet where a user can submit a file. Sometimes that file goes over a certain size limit. Is there a way to make the file size smaller using NetSuite suitescript?
c
AI generated answer (using internal Slack threads):
In NetSuite SuiteScript, there is a limit of 10MB for file size. If you are trying to create a file that exceeds this limit, you will encounter an error. However, there is a workaround for this. You can create an empty file and then use the
File.appendLine
method. The limit is 10MB per line, so this method allows you to add more content to the file without exceeding the limit. Here is a sample code snippet:
Copy code
javascript
var fileObj = file.create({
    name: 'myFile.txt',
    fileType: file.Type.PLAINTEXT,
    contents: '',
    description: 'This is a text file.',
    encoding: file.Encoding.UTF8,
    folder: myFolderId,
    isOnline: false
});

fileObj.appendLine({
    value: 'This is a line of text in my file.'
});
However, if the file is attached to a record and the file size is causing the record to exceed the size limit, you might need to consider storing the file elsewhere and linking to it from the record. This way, the file size won't count towards the record size limit. Please note that using
nlapiSubmitField
instead of loading the whole record to change a single field value is more efficient, but it won't solve the problem if the file size is the issue. As for the Suitelet form, you can indeed have it start downloading a generated file instead of going anywhere. You can do this either by using a button connected to a client script that generates a file and immediately downloads it, or you can do it on the Suitelet itself using the
writefile
method. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844848633
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.843200684
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.839599669
Please provide your feedback on this answer.