give and example of : perform a search/SuiteQL whe...
# ask-stanley-ai
r
give and example of : perform a search/SuiteQL whenever possible to reduce the time and governance units consumed by your script
c
AI generated answer (using internal Slack threads):
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ****** Performing a search or using SuiteQL can significantly reduce the time and governance units consumed by your script. Here's an example: When you need to retrieve a large amount of data, using SuiteQL can be more efficient than using the search module. SuiteQL allows you to define queries that might be impossible with a single saved search, and its performance is generally better. For instance, a recent test showed that SuiteQL could retrieve 100,000 rows in just 0.53 seconds, while using the search module for every X,000 rows could take tens of seconds to minutes, depending on the search parameters and dataset being called. Here's a sample SuiteQL code:
Copy code
javascript
var suiteQL = "SELECT * FROM transaction WHERE subsidiary = 1";
var suiteQLResultSet = query.runSuiteQL(suiteQL);
var suiteQLResult = suiteQLResultSet.asMappedResults();
In this example, the SuiteQL query retrieves all transactions for a specific subsidiary. The
query.runSuiteQL(suiteQL)
method runs the SuiteQL query, and the
asMappedResults()
method returns the results as an array of objects, where each object represents a row of data. However, if you only need a few fields from a record, you can use the
lookupFields
operation, which is more efficient than a search or record load. For example:
Copy code
javascript
var recordType = 'salesorder';
var recordId = '12345';
var fields = ['entity', 'total'];
var result = record.lookupFields({
    type: recordType,
    id: recordId,
    columns: fields
});
In this example, the
lookupFields
operation retrieves the 'entity' and 'total' fields from a sales order record with the ID '12345'. This operation is faster and consumes fewer governance units than loading the entire record or performing a search. Remember, the choice between SuiteQL, search, and
lookupFields
depends on your specific needs and the size of the data you're dealing with.
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826217473
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.825600088
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.822869241
Please provide your feedback on this answer.