Whether you're preparing a targeted marketing campaign, identifying customers for product upgrades, or analyzing purchasing trends, knowing who has purchased a specific item is a common reporting requirement. SuiteQL provides a flexible and efficient way to retrieve this information directly from the database.
SuiteQL Query
The query below returns a list of customers who have purchased a specific item, identified by its internal ID.
SELECT
c.id, -- Customer internal ID
c.entityid, -- Customer ID/Number
c.companyname -- Customer name
FROM
customer c
WHERE EXISTS (
SELECT 1
FROM
transaction t
INNER JOIN transactionLine tl
ON tl.transaction = t.id -- Join transaction lines to the transaction header
WHERE
-- Match the Sales Order to the current customer
t.entity = c.id
-- Only include Sales Orders
AND t.type = 'SalesOrd'
-- Replace 123 with the internal ID of the item you want to search for
AND tl.item = 123
);
To easily execute a SuiteQL query, see NetSuite Admin Tip | Running SUITEQL Using a Suitelet
DISCLAIMER: 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.
We’d love to hear how you integrate SuiteQL into your NetSuite processes! Share your insights and experiences in the NetSuite Admin Corner.