SuiteQL, an advanced query language used in NetSuite, provides powerful capabilities for querying and manipulating data. One common task is to transform or clean up data as it's retrieved from the database. In this article, we’ll demonstrate how to use the SuiteQL REPLACE function to modify field values in a customer record. Specifically, we'll show how to replace a substring in the EntityStatus field of customer records.
We aim to retrieve customer records, displaying the customer ID, company name, and a cleaned-up version of the EntityStatus field. The EntityStatus field contains values prefixed with "Customer-", which we want to remove for clarity.
Here’s the SuiteQL query that accomplishes this:
SELECT ID, CompanyName AS Name,REPLACE( BUILTIN.DF( EntityStatus ), 'Customer-', '' ) AS CompanyStatus FROM Customer
Query Breakdown
- SELECT ID, CompanyName AS Name: This part of the query selects the customer ID and the company name, renaming the CompanyName field to Name for simplicity.
- REPLACE(BUILTIN.DF(EntityStatus), 'Customer-', '') AS CompanyStatus: This section uses the REPLACE function to remove the "Customer-" prefix from the EntityStatus field. The BUILTIN.DF function is used to format the field value as a string before applying the REPLACE function. The cleaned value is then aliased as CompanyStatus.
- FROM Customer: This specifies the Customer table as the source of the data.
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.
Do you have any other way on how to change the field value in SuiteQL? Feel free to share them here!
If you find this information useful, let us know by reacting or commenting on this post! Thank you!