ServerResponse Header Setting in SuiteScript

Learn to set HTTP headers using ServerResponse in SuiteScript with required parameter details.

·2 min read·View Oracle Docs

Setting HTTP headers using ServerResponse.setHeader in SuiteScript is essential for customizing server responses effectively. This method allows you to define headers that can specify language preferences, control caching, and more.

How to Set HTTP Headers with ServerResponse

The ServerResponse.setHeader(options) method in SuiteScript lets you assign the value of a response header. This is useful in server scripts to manage client-server communication effectively.

Supported Script Types

  • Compatible with server scripts

Parameters Required

  • options.name: This is a required string that represents the name of the header (e.g., 'Accept-Language').
  • options.value: This is a required string that contains the header value you wish to set (e.g., 'en-us').

Error Codes

  • SSS_INVALID_HEADER: Thrown when the header name or value is invalid.
  • SSS_MISSING_REQD_ARGUMENT: Thrown if options.name or options.value is omitted.

Example Usage

suitescript
serverResponse.setHeader({
name: 'Accept-Language',
value: 'en-us',
});

Note: Substitute the 'Accept-Language' and 'en-us' with your desired header name and value.

Related Topics

For more details, refer to the [N/http Module], [http.ServerResponse], and explore HTTP header information and various SuiteScript 2.x concepts.

Who This Affects

This information is particularly relevant for:

  • NetSuite Administrators
  • Developers working with SuiteScript

Key Takeaways

  • Easily set and manage HTTP headers in server scripts using ServerResponse.setHeader.
  • Ensure to provide both header name and value to avoid errors.
  • Features are available since SuiteScript version 2015.2.

Frequently Asked Questions (4)

What permissions are required to use the N/http module in SuiteScript?
The article does not specify any particular permissions required to use the N/http module. It mentions that the `setHeader` method can be used in server scripts without governance restrictions.
How do I handle errors with the setHeader method in SuiteScript?
When using the `setHeader` method, you may encounter errors such as `SSS_INVALID_HEADER` if the header name or value is invalid, and `SSS_MISSING_REQD_ARGUMENT` if the `options.name` or `options.value` parameter is not specified.
Can I set any HTTP header using the setHeader method in SuiteScript?
No, there are restrictions on setting certain HTTP headers manually. Headers like `Connection`, `Content-Length`, and `Host` cannot be set using the `setHeader` method, and any attempt to set such headers will result in discarded values.
Is the setHeader method applicable to all script types in SuiteScript?
The `setHeader` method is only applicable to server scripts in SuiteScript. Other script types are not mentioned in the context of this method.
Source: Parameters 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 Administration

View all Administration articles →