ServerResponse Object Members in SuiteScript 2.x
The ServerResponse object in SuiteScript 2.x facilitates handling server responses, enabling effective integration with HTTPS requests.
The ServerResponse object in SuiteScript 2.x is critical for managing server responses within HTTPS calls. It allows developers to interact efficiently with the responses received from Suitelets or RESTlets, which can include rendering PDFs, writing content, and setting response headers.
What Is the ServerResponse Object?
The ServerResponse object encapsulates the response from an HTTPS server to an HTTPS request. It provides various methods and properties that you can use to manipulate the outgoing response in your Server scripts.
Key Methods of ServerResponse
The following table outlines the main methods available in the ServerResponse object:
| Method Name | Description |
|---|---|
addHeader(options) | Adds a header to the response. |
getHeader(options) | Returns the value of a specified response header. |
renderPdf(options) | Generates and sends a PDF directly as a response. |
sendRedirect(options) | Sets a redirect URL to a specified NetSuite resource. |
setCdnCacheable(options) | Controls CDN caching for a defined period. |
setHeader(options) | Sets the value for a response header. |
write(options) | Writes text/xml/html information to the response. |
writeFile(options) | Sends a file in the response. |
writeLine(options) | Writes line information (text/xml/html) to the response. |
writePage(options) | Generates a page as part of the response process. |
Properties of ServerResponse
The ServerResponse object also includes a read-only property:
headers: This property returns all headers associated with the server response.
Important Considerations
- Ensure that your use of headers complies with NetSuite's restrictions, as certain headers cannot be altered or added. Attempting to set blocked headers will result in an error.
- Remember to handle secure data appropriately; avoid using plain text credentials in your responses and consider leveraging Token-based Authentication (TBA) or OAuth 2.0 for enhanced security.
Key Takeaways:
- The ServerResponse object is essential for handling HTTP responses in SuiteScript 2.x.
- Key methods allow for header management, response writing, and generating PDFs.
- Ensure compliance with response header restrictions to avoid errors in your scripts.
Frequently Asked Questions (4)
How can I add a header to the server response in SuiteScript 2.x?
What method would I use to write a file as part of the server response?
Are there restrictions on modifying headers in the ServerResponse object?
Can the ServerResponse object be used for generating PDFs in SuiteScript 2.x?
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