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.

Example

take the first result of a search as a plain object (ImmutableJS)

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

Hierarchy

  • LazySearch

Implements

  • IterableIterator<search.Result>

Constructors

  • Not meant to be used directly, use factory methods such as load or from

    Parameters

    • search: Search

      the netsuite search object to wrap

    • pageSize: number = 500

      optional pagesize, can be up to 1000

    Returns LazySearch

Properties

currentData: Result[]
currentPage: Page
index: number
log: Logger
pageSize: number = 500

optional pagesize, can be up to 1000

pagedData: PagedData
search: Search

the netsuite search object to wrap

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.

    Returns

    Example

    create a search and begin lazy processing of results

    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))

    Parameters

    • search: Search
    • Optional pageSize: number

    Returns LazySearch

  • Loads an existing NS search by id and prepares it for lazy evaluation

    Returns

    Example

    do something for each search result, automatically exiting if out of governance.


    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))

    Parameters

    • id: string

      internal id of the search to load

    • Optional pageSize: number

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

    Returns LazySearch

Generated using TypeDoc