Makes a NetSuite search an ES2015 style Iterator. That is, it follows the Iterator Protocol for iterating over search results in a forward-only fashion. The result can be passed to any library that accepts Iterators (such as ImmutableJS) to provide easy chainable logic on arbitrary length search result sets.

Started with this as a class due to other library requirements and left it as a class just as an easy way to contain state about currentpage and index into that page.

This is exposed as an iterator so that it could be used with other libraries. For example I've heard Ramda may support iterators so if we choose to go a more pure FP route down the road this class would be useful - i.e. it remains untied to any particular library.

import {Seq} from './NFT-X.Y.Z/immutable'
const oneResult = Seq(LazySearch.load('1234')).map(nsSearchResult2obj()).take(1)

Implements

  • IterableIterator<search.Result>

Properties

currentData: Result[]
currentRange: Result[]
executedSearch: ResultSet
index: number
log: Logger
nextPageStart: number = 0
totalSearchResultLength: number = 0
LOGNAME: string = 'lazy'

the name of the custom logger for this component for independent logging control

Methods

  • LazySearch is both an iterable and an iterator for search results.

    Returns IterableIterator<Result>

  • per the iterator protocol, retrieves the next element. Also returns null if done as the specification for the protocol says the value property is optional when 'done'

    You don't typically call this function yourself - libraries like ImmutableJS do.

    Returns IteratorResult<Result, any>

  • Creates a lazy search from an existing NS search.

    Parameters

    • search: Search
    • OptionalpageSize: number

    Returns LazySearch

    import {Seq} from './NFT-X.Y.Z/immutable'
    import * as search from 'N/search
    import {governanceRemains, LazySearch, nsSearchResult2obj} from './NFT-X.Y.Z/search'

    Seq(LazySearch.from(search.create({
    filters: [['internalid', 'anyof', [1,2]),
    columns:['item', 'description'],
    type: search.Type.ITEM,
    })))
    .takeWhile(governanceRemains()) // process until we drop below default governance threshold
    .map(nsSearchResult2obj()) // convert search results to plain objects with properties
    .forEach( r => log.debug(r))
  • Loads an existing NS search by id and prepares it for lazy evaluation

    Parameters

    • id: string

      internal id of the search to load

    • OptionalpageSize: number

      how many records to retrieve per page (paging is automatic) Maximum value: 1000

    Returns LazySearch


    import {Seq} from './NFT-X.Y.Z/immutable'
    import {governanceRemains, LazySearch, nsSearchResult2obj} from './NFT-X.Y.Z/search'

    Seq(LazySearch.load('1234'))
    .takeWhile(governanceRemains()) // process until we drop below default governance threshold
    .map(nsSearchResult2obj()) // convert search results to plain objects with properties
    .forEach( r => log.debug(r))