When building Suitelets, you may occasionally need to capture the IP address of the user accessing the page—whether for security auditing, regional customization, or analytics and tracking purposes. Fortunately, NetSuite includes the client’s IP address in the request headers when the Suitelet is accessed through a web browser.
By referencing the ns-client-ip header, you can easily extract and log the IP address of the user in your script.
This technique can be valuable for:
Identifying suspicious or unauthorized access.
Logging IPs for compliance or audit trails.
Tailoring content or services based on user location.
Note: This method only works when the Suitelet is accessed via a browser.
Here's a quick example using SuiteScript 2.x:
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(['N/ui/serverWidget'], function(widget) {
function onRequest(context) {
// Retrieve the IP address from the request headers
context.request.headers['ns-client-ip'];
// Log the entire headers object (optional)
log.debug({ title: 'Request Headers', details: context.request.headers });
// Log the IP address
log.debug({ title: 'Client IP Address', details: ip });
}
return {
onRequest: onRequest
};
});
For more information on handling scripts, refer to the following:
The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect, or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
Have you ever used IP address tracking in your Suitelets? Whether it’s for security, customization, or analytics—share your tips and use cases with fellow members in the NetSuite Admin Corner!