Resources / Article

NetSuite RESTlet saved search filters

Pass filters to a NetSuite saved search through a RESTlet GET: encode values, validate fields and operators, append filters, and page with runPaged.

Pass filters as query-string parameters on the RESTlet GET call, then append them to the loaded saved search as search.createFilter entries. Validate every field, operator and value before the search runs, and page large results with runPaged.

How do you pass filters to a saved search through a RESTlet GET?

Start with the contract. A filter has three parts: a field ID, an operator and a value. Write that contract into the interface spec, for example in the BRD template, so the caller and the RESTlet agree on names such as from, to, minAmount and subsidiary.

RESTlets are SuiteScripts that NetSuite runs when an external system calls them, and they can return data to that caller (RESTlet scripts). When you save a deployment, NetSuite gives you the call URL, and you call it with get, post, put or delete (RESTlet reference). RESTlets support search operations alongside get, add and update (integration options).

Inside the RESTlet, load the saved search and append filters. The exact request object and enum names depend on your SuiteScript version and entry point definition, so check them in the account against the RESTlet reference.

define(['N/search'], (search) => {
  const get = (params) => {
    const s = search.load({ id: params.search });

    if (params.from) {
      s.filters.push(search.createFilter({
        name: 'trandate',
        operator: search.Operator.ONORAFTER,
        values: [params.from]
      }));
    }

    if (params.subsidiary) {
      s.filters.push(search.createFilter({
        name: 'subsidiary',
        operator: search.Operator.ANYOF,
        values: [params.subsidiary]
      }));
    }

    const paged = s.runPaged({ pageSize: 500 });
    const rows = [];

    paged.pageRanges.forEach((range) => {
      paged.fetch({ index: range.index }).data.forEach((r) => {
        rows.push({
          id: r.id,
          amount: r.getValue({ name: 'amount' })
        });
      });
    });

    return rows;
  };

  return { get };
});

Encode each query value with encodeURIComponent before you build the URL. Spaces in a subsidiary name, commas in a date list and plus signs in a search name all break a raw query string. For compound logic, push an array expression such as ['and', ['trandate', 'onorafter', '2025-04-01'], ['amount', 'greaterthanorequal', '500000']], then test it against the saved search UI.

Validate on the server side. Keep a whitelist of field IDs and operators. Reject an unknown field, an operator that does not match the field type, and a date in the wrong format. Return a short error that names the bad parameter. This keeps a typo in an integration from turning into a full-table search.

Page with runPaged. It returns page ranges, and you fetch each page by index. Append rows in order, or write each page to your target. Check the page count against the saved search result count in the UI.

Passing filters to a saved search through a RESTletThe caller sends a GET with query-string parameters such as search, from, to, min and subsidiary, values encoded. The RESTlet validates each field, operator and value against a whitelist, loads the saved search, appends one search.createFilter per parameter to the saved search's own filters, then pages with runPaged and fetches each page range. Rows come back to the caller.Caller: GET with encoded query-string parameters:search, from, to, min, subsidiaryRESTlet validates: whitelist of field IDs andoperators, date format, valueLoads the saved search and pushes onesearch.createFilter per parameter. They combine withthe search's own filtersrunPaged: loop the page ranges and fetch each page byindexRows returned: only the keys the caller needs
A filtered saved search through a RESTlet GET, from query string to paged rows.

Example

A partner in Pune has a client with open receivables. The client wants rows above INR 5,00,000 (5 lakh) for one subsidiary, from 1 April 2025 to 31 March 2026. The saved search ID is customsearch_ar_open.

The GET call looks like this:

https://<account>.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=123&deploy=1&search=customsearch_ar_open&from=2025-04-01&to=2026-03-31&min=500000&subsidiary=7

The RESTlet loads customsearch_ar_open, appends a trandate filter with ONORAFTER for from, a trandate filter with ONORBEFORE for to, an amount filter with GREATERTHANOREQUAL for min, and a subsidiary filter with ANYOF for subsidiary. It then pages the result set and returns the internal ID, customer, date and amount for each row.

For date ranges tied to the Indian financial year, set the default range in the saved search itself and let the RESTlet override it only when the caller sends both dates. That keeps a stray from from producing an open-ended query. The go-live date guide is useful when the client's fiscal calendar and the integration calendar differ.

Trade-offs

GET is easy to test in a browser and easy to log. Long filter sets hit URL length limits in clients and proxies, so a GET with twenty filters is a poor fit. Use POST for a long JSON body and keep GET for a handful of parameters.

A saved search keeps filter logic in one place, which suits a shared client search. An ad hoc search object gives the RESTlet full control, at the cost of duplicating logic that already exists in the saved search. Pick one owner for the logic and document it.

runPaged returns pages, so memory stays flat and each page is a separate fetch. That is good for large result sets. Watch concurrency and governance, because the integration options page notes that RESTlet and web services limits are managed together (integration options).

Common mistakes

The pattern appears in public threads:

"Pass NetSuite saved search filter parameters through RESTlet API GET request" (Stack Overflow).

FAQ

Should the RESTlet use GET or POST for filters?
Use GET for a small, readable set of parameters and POST for a long JSON payload. RESTlets accept both methods, and the call URL comes from the deployment record (RESTlet reference).

Why does a filter work in the saved search UI and fail in the RESTlet?
The UI can carry context filters that the RESTlet does not send. Load the saved search, inspect its existing filters, then append your parameter and test the same values in the UI.

How do I return more than one page of rows?
Use runPaged, loop over pageRanges, and fetch each page by index. The RESTlet returns the combined rows or writes each page onward.

Can I pass a full filter expression as JSON?
Yes, parse the JSON, validate each field and operator against a whitelist, then push the expression onto the saved search filters. Keep the parser strict.

The quick way is mark.: it reads the saved search and RESTlet deployment, finds why the filter is dropped, and tells you the exact fix. Try it free.

Sources

  1. docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_0303103129.html
  2. docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1544786256.html
  3. docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_160514060027.html
  4. docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_161556508008.html
  5. docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_164737468057.html
  6. docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4618434109.html

Have mark. check this against the client's own files

mark. reads the client's files and sets each point against them, with the source beside it.

Book a working session

Twenty minutes on one client folder. Your 21-day trial opens on the call.

Start your free trial

Three questions, and Mark opens an account for you on NetSuite.

Which ERP do your clients run?

Your account opens within one working day.