ANS-1076 · SUITESCRIPT DEVELOPMENT
How to Find Contact Emails on NetSuite Transactions Using SuiteScript
This guide outlines a SuiteScript 2.x approach to programmatically identify and extract contact email addresses linked to specific NetSuite transaction records.
Short answer
To retrieve contact emails associated with a NetSuite transaction, perform a joint search on Contact records. Filter this search by the transaction's internal ID. Utilize SuiteScript 2.x's "N/search" module, specifically "search.createColumn('email')" and "search.createFilter('internalid', 'transaction', 'is', recordId)" to define your search criteria and extract the relevant email addresses.
Scenario
NetSuite users often need to programmatically access contact information, specifically email addresses, that are directly linked to a transaction record. While contacts are visible under the 'Relationships' tab on a transaction, directly querying these associated emails via standard transaction fields can be challenging. A common requirement is to retrieve these contact emails for custom reporting or integration purposes.
Solution
To retrieve contact emails associated with a specific transaction, a joint search on Contact records can be performed, filtered by the transaction's internal ID. In SuiteScript 2.x, this is accomplished using the "N/search" module. The following snippet demonstrates how to define the search columns and filters within a SuiteScript 2.x context:
javascript
// This code snippet assumes the 'N/search' module has been loaded,
// for example, via define(['N/search'], function(search) { ... });
var columns = [];
var filters = [];
var result = null;
columns[0] = search.createColumn({ name: 'email' });
filters[0] = search.createFilter({
name: 'internalid',
join: 'transaction',
operator: search.Operator.IS,
values: recordId
});The "recordId" variable in the filter should be replaced with the internal ID of the specific transaction for which contact emails are being sought.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
