When working with SuiteQL to analyze Purchase Orders, you may want to include additional information about related Entities (e.g., Vendors) and Employees (e.g., Sales Reps). However, not all Purchase Orders are associated with an Employee, so it's important to structure your joins correctly.
This guide demonstrates how to build a SuiteQL query that pulls Purchase Orders along with:
- The Entity (Vendor) information — always required.
- The Employee information — if available.
INNER JOIN vs LEFT OUTER JOIN:
- INNER JOIN (Entity): Ensures that only transactions with a valid associated entity are returned. This is appropriate for the Entity join, as all Purchase Orders are expected to have one.
- LEFT OUTER JOIN (Employee): Allows transactions to be returned even if no Employee is associated — which is common for many Purchase Orders.
Sample Query
SELECT
Transaction.TranID,
Transaction.ID AS InternalID,
Transaction.TranDate,
Transaction.TranDisplayName AS TransactionName,
BUILTIN.DF( Transaction.Type ) AS Type,
BUILTIN.DF( Transaction.Status ) AS Status,
BUILTIN.DF( Transaction.Entity ) AS Entity,
BUILTIN.DF( Transaction.Employee ) AS Employee,
BUILTIN.DF( Entity.Type ) AS EntityType,
BUILTIN.DF( Entity.Phone ) AS EntityPhone,
Employee.Title AS EmployeeTitle,
Employee.Phone AS EmployeePhone,
Employee.Email AS EmployeeEmail
FROM
Transaction
INNER JOIN Entity ON
( Entity.ID = Transaction.Entity )
LEFT OUTER JOIN Employee ON
( Employee.ID = Transaction.Employee )
WHERE
Transaction.Type='PurchOrd'
This query:
- Retrieves all Purchase Order transactions.
- Joins to the Entity table to return details such as type and phone number.
- Optionally joins to the Employee table, returning their contact info only if the PO has an associated Employee
To easily execute a SuiteQL query, see NetSuite Admin Tip | Running SUITEQL Using a Suitelet
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.