ServerResponse Write File Method in SuiteScript
The ServerResponse writeFile method in SuiteScript allows server scripts to write files to HTTP responses, facilitating file downloads.
The writeFile method of the ServerResponse object in SuiteScript enables developers to write files to HTTP responses. This is useful when building Suitelets or server-side scripts that need to output files for download or inline display to users.
Method Overview
- Method Description: Writes a file to the response without returning any value.
- Supported Script Types: This method is compatible with server scripts.
- Governance: There are no governance limits associated with this method.
Parameters
The method accepts an options parameter, which is a JavaScript object comprising the following key properties:
| Parameter | Type | Required / Optional | Description |
|---|---|---|---|
options.file | file.File | Required | A file.File object to write to the response. |
options.isInline | boolean | Optional | If true, the file is presented inline; defaults to false. |
Note: The options.file parameter must be specified as a file.File object, which you can create using the file module.
Error Handling
Several error codes may be thrown by the writeFile method:
SSS_MISSING_REQD_ARGUMENT: Thrown if the requiredoptions.fileparameter is missing.WRONG_PARAMETER_TYPE: Raised when the providedoptions.fileis not a validfile.Fileobject.
Usage Example
Here’s a basic example of how to use the writeFile method within a SuiteScript:
1// Sample code to write a file response2var serverResponse; // Assume this is your instance of ServerResponse3var myFileObj = file.load({ id: '12345' }); // Load your file object4 5serverResponse.writeFile({6 file: myFileObj,7 isInline: true8});This code demonstrates how to load a file and then write it to the response, which can be utilized in scenarios like file downloads or displaying files directly in a browser window.
Related Topics
- http.ServerResponse
- N/http Module
- SuiteScript 2.x Modules
Key Takeaways
- The
writeFilemethod handles file outputs in server scripts, allowing dynamic file downloads. - It's vital to ensure the file is loaded as a
file.Fileobject before using it. - Error handling is important to manage required parameters and data types effectively.
Frequently Asked Questions (4)
What script types support the ServerResponse writeFile method?
Is there a governance limit for using the writeFile method in SuiteScript?
What errors might occur if the required parameters for writeFile are not provided correctly?
How do you specify a file to write to the response using the writeFile method?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Custom Tool Script Enhancements in NetSuite
Custom tool scripts in NetSuite gain execution log support and a new management page in February 16, 2026.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
