ANS-0828 · WEB SERVICES & INTEGRATIONS
How to Retrieve Contact Roles and Associated Customers via NetSuite Web Services?
Understand the process of searching Contact records, joining with Customer data, and filtering results using SuiteTalk SOAP API.
Short answer
To retrieve Contact Roles and their associated Customers via NetSuite Web Services, perform a search on Contact records. Include the "ContactRole" field and join the search with Customer records. Filter the results to ensure the joined Customer matches the Customer specified in the Contact body field, allowing precise role association.
Scenario
Users need to programmatically access contact roles associated with specific customers within NetSuite. The challenge involves identifying the correct search criteria and join operations using NetSuite Web Services (SuiteTalk SOAP API) to accurately link contact roles to their respective customer records.
Solution
To retrieve Contact Roles and their associated Customers using NetSuite Web Services, follow these steps:
Initiate a search on Contact records, which inherently includes the "ContactRole" field. This field will return all roles associated with a given customer.
To determine which specific Customer a role applies to, perform a join operation on the Customer record. This will link the contact role to its corresponding customer.
To ensure that only the role applicable to the Customer specified in the Contact body field is returned, refine the search. This involves joining on any Customer and subsequently filtering the search results to include only those where the Joining Customer equals the one defined in the Contact Body field.The following Java code snippets illustrate how to set search columns and filter results. Please note that due to updates in the NetSuite WSDL and client library generation since 2017, the precise method signatures and navigation paths for retrieving values may vary in current implementations.
crsrb.setContactRole(new SearchColumnSelectField[] { new SearchColumnSelectField() });crsrb.setCompany(new SearchColumnSelectField[] { new SearchColumnSelectField() });CustomerSearchRowBasic customerJoinColumn = new CustomerSearchRowBasic();customerJoinColumn.setInternalId(new SearchColumnSelectField[] { new SearchColumnSelectField() });Later in the process, when retrieving the response value, a filtering condition can be applied:
if (!((ContactSearchRow) row).getBasic().getCompany(0).getSearchValue().getInternalId().equals(((ContactSearchRow)row).getCustomerJoin().getInternalId(0).getSearchValue().getInternalId())){ continue;}Expert NetSuite Support
Need help with this NetSuite issue?
Web Services & Integrations consulting and configuration support
