Using the ServerResponse Write Method in SuiteScript 2.x
Learn how the ServerResponse write method outputs text, XML, or HTML in SuiteScript 2.x, for effective server responses.
The ServerResponse write method is a key tool in SuiteScript that allows developers to send text, XML, or HTML back through the server response. This method is particularly useful in server scripts where formatted output is necessary for user interactions or API responses.
Method Description
This method takes only strings as input. If you need to send a file, you should use the ServerResponse.writeFile(options) method instead.
Returns
The method does not return any value (void).
Supported Script Types
- Server scripts
Governance
There are no governance limits associated with this method, making it flexible for frequent use.
Module
This method is part of the N/http Module, which handles HTTP functions in SuiteScript.
Parent Object
The write method belongs to the http.ServerResponse object.
Parameters
The options parameter is required and must be a JavaScript object containing the following:
| Parameter | Type | Required | Description |
|---|---|---|---|
options.output | string | required | The string being written. |
Errors
Developers should account for the following errors when using this method:
-
Error Code:
SSS_MISSING_REQD_ARGUMENT- Message: Missing a required argument: {param name}
- Thrown If: The
options.outputparameter is not specified.
-
Error Code:
WRONG_PARAMETER_TYPE- Message: {param name}
- Thrown If: The value input for
options.outputis not a string.
Syntax Example
Here’s a simple code example demonstrating how to use the write method:
1// Add additional code 2...3serverResponse.write({4 output: 'Hello World'5});6...7// Add additional codeThis code snippet illustrates the basic syntax without extending into a full functional application. For more complete examples, refer to the N/http Module Script Samples.
Related Topics
- http.ServerResponse
- N/http Module
- SuiteScript 2.x Modules
Key Takeaways
- The
writemethod outputs strings in SuiteScript responses. - It can only accept string input and does not handle files directly.
- Be mindful of common errors, such as missing parameters or incorrect types.
- Refer to the N/http Module for comprehensive usage examples.
Frequently Asked Questions (4)
What types of output can be generated using the ServerResponse write method in SuiteScript?
Is it possible to use the ServerResponse write method to send files?
Are there any governance limits associated with the ServerResponse write method?
What error might be encountered if the output parameter is omitted when using the ServerResponse write method?
Was this article helpful?
More in SuiteScript
- Common SuiteScript Errors and Solutions for NetSuite
Common NetSuite script errors include INVALID_SCRIPT_DEPLOYMENT_ID and SSS_AUTHORIZATION_HEADER_NOT_ALLOWED. Learn effective solutions.
- Set Sublist Field Values in SuiteScript 2.x for Record Management
Set sublist field values in SuiteScript 2.x for effective record management using standard and dynamic modes.
- Setting Field Values in SuiteScript for Effective Record
Learn to set field values in SuiteScript effectively, troubleshooting common errors and understanding data types.
- SuiteScript 2.1 Enhancements and API Updates in NetSuite
SuiteScript 2.1 enables execution of 2.0 scripts and supports PATCH method for enhanced API capabilities.
Advertising
Reach SuiteScript Professionals
Put your product in front of NetSuite experts who work with SuiteScript every day.
Sponsor This Category