Running Searches in Config

This section covers the syntax and patterns for defining and resolving searches within config.

Important:

Config searches are limited to a maximum of 1,000 return values or records. Be sure to manage your search criteria so you don't reach this limit and cause errors. For more information, see Search Result Limits.

Basic Syntax

To understand the syntax of a simple search, we'll use the sample below:

            {
  "record": "supportcase",
  "filters": ["internalid","anyof","${event.supportcase || 0}"],
  "map": {
    "id": "internalid",
    "label": "casenumber"
  }
} 

          

The record property sets the search type to run or the record type to search for. In the sample above, we’re searching for Case records. You can find the ID of the record or search type using the NetSuite record browser. For more information see, Working with the SuiteScript Records Browser.

The filters property sets the search criteria.

The map property sets what results will be returned. In this example, you’ll get back an object with two properties: id and label.

Special Characters in map

You can use special characters in the map section to change how the search results work. Here are some of those characters:

Note:

When you use special characters, remember that they work the same way they do in NetSuite. For example, using group means all other fields you want to return results need to be grouped, counted, or summed. If you use these, it is best practice to have all results grouped or summarized.

Character

Usage

=

Get value

#

Get text value (label)

[ ]

Get array values (multiselect)

*

Merge search result duplicates of this column value

<

Sort in ascending order

>

Sort in descending order

^

Group by maximum value

?

Count

+

Sum

~

Average

{

Minimum

}

Maximum

!

Write a value even if it hasn't changed

Get value and Get text

The equals (=) character lets you get a field's value. For example, if you’re mapping a select field, this returns the internalid of the selection. Most of the time, the value is returned by default, but the = character makes it more specific.

The number sign (#) character lets you get the field's text instead. With a select field, this returns the label of the selection as you see it in the NetSuite UI.

Multiselect or arrays

The square bracket ([ ]) characters return the result as an array. They are usually used to ensure that the selected options are returned as an array, rather than as a comma-separated list.

Pipe

The pipe (|) character lets you control where the property reads from and where it writes to, separately. It is handy when you need to read from one field but write to another, or when the same field has two different IDs for searching and writing. Another common use for the pipe character is to make sure you can read a field value but not write to it.

Here's an example search that reads from one field and writes to another:

            "quantity": "quantity|item.quantity" 

          

Here's an example search that only reads the field value:

            "status": "status#|" 

          

Nested Searches

You can use results from one search in the filters of another search. The nested search runs first and returns an array of internal IDs, then the outer search uses those IDs in its filter.

Important:

If you nest searches the wrong way, it can cause performance issues.

Special Nested Search Properties

The all and default properties are a couple of special search options you’ll use often. By default, config searches return up to 1000 results. If you set all: true, you can get more than 1000, but it might slow things down. If there are no results results, config returns an empty array, which might cause errors. The default property gives you a fallback value instead.

The example below shows a second search inside another. The second search is on the record customrecord_nxc_cr and returns a map of custrecord_nxc_cr_asset. This field stores the asset and therefore returns the internal ID of the asset found on the record. It uses a default of 0 to avoid issues if there are no results found in the nested search. Any results found are an array of assets internal IDs, and get excluded from the main search because the nested search is inside of this filter: ["internalid","noneof",

            "record": "customrecord_nx_asset",
                                    "filters": [
                                        ["internalid","anyof","${event.caseassets}"],"and",
                                        ["internalid","noneof",{
                                                "array": true,
                                                "default": "0",
                                                "assets": {
                                                    "record": "customrecord_nxc_cr",
                                                    "filters": [
                                                        ["custrecord_nxc_cr_case","anyof","${event.supportcase}"],"and",
                                                        ["custrecord_nxc_cr_task","noneof","${event.internalid}"]
                                                    ],
                                                    "map": "custrecord_nxc_cr_asset"
                                                }
                                            }]
                                    ], 

          

Related Topics

General Notices