Hi all, just a curious question. Does anyone have...
# suitescript
d
Hi all, just a curious question. Does anyone have a framework/pattern when making 'search' API calls? I've got a few I could share, just wondered if anyone else has come up with any?
e
Not 100% sure what you're looking for, but I do my best not to abstract the search API too far. That said, there are a few things I do very consistently: 1. Nearly all my searches leverage Filter Expressions and string-based Column names (as opposed to using
createColumn()
and
createFilter()
2. Almost every search is encapsulated in its own function named
find*
(e.g.
findOrders
) and looks very much like:
Copy code
s.create(...)
  .run()
  .getRange(...)
  .map(resultToObject);
d
That's preciously where I'm at right now ... was asking the community to see if there was something I hadn't thought of yet.
d
I agree with the above approach as well, generally what we use. we have dabbled in creating a wrapper around search functionality with base "class" and extending from there etc. to mess with OOP and inheritance but generally does not seem worth the overhead. but I guess it depends on the scope of your project and what someone could potentially gain from additional framework
main takeaway imo is abstraction of data retrieval methods to their own single-responsibility function that returns a reliable array of objects with consistent structure; idea there for us at least is we could swap out implementation with N/query or SuiteQL if was needed and maintain/extend same functionality with relative ease
s
umm, running searches is such a common case it's part of NFT https://github.com/ExploreConsulting/netsuite-fasttrack-toolkit-ss2#lazy-search
the pattern surfaced by NFT currently is searches are a lazy sequence of JS objects, typically consumed by ImmutableJS and the dozens of well known functions contained therein.
under the covers LazySearch just presents an 'iterator protocol' compatible view of a search of arbitrary size (i.e. auto paging)... and hence can be consumed by any library that understands the iterator protocol. ImmutableJS is just one such lib.
t
Here's how I've been handling that. This is part of a RESTlet that provides access to customer data. The call to the RESTlet can include an array of filters to be applied to the search, and an array of columns to be returned. So it's very flexible.
However, I very rarely use "search" for new integration projects. Instead, I'm using SuiteQL queries. I blogged about that recently, and mentioned some of the advantages of this approach: https://timdietrich.me/blog/netsuite-suiteql-restlet/