ServerResponse Object Members in SuiteScript 2.x

The ServerResponse object in SuiteScript 2.x facilitates handling server responses, enabling effective integration with HTTPS requests.

·2 min read·View Oracle Docs

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 NameDescription
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?
In SuiteScript 2.x, you can add a header to the server response using the `addHeader(options)` method of the ServerResponse object.
What method would I use to write a file as part of the server response?
To send a file as part of the server response, you can use the `writeFile(options)` method provided by the ServerResponse object.
Are there restrictions on modifying headers in the ServerResponse object?
Yes, there are restrictions on modifying certain headers in NetSuite. Attempting to set headers that are blocked by NetSuite can result in an error.
Can the ServerResponse object be used for generating PDFs in SuiteScript 2.x?
Yes, you can use the `renderPdf(options)` method of the ServerResponse object to generate and send a PDF directly as a response.
Source: ServerResponse Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Integration

View all Integration articles →