Running Searches in Config

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

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 criteria for the search.

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. The table below lists some of these characters:

Note:

When using special characters, remember that they will operate in the same way they do within NetSuite. For instance, using group requires that all other fields you want to return results to be also grouped or counted/summed. If you use this type of character, 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 the value of a field. 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 lets you be more specific.

The number sign (#) character lets you get the text of a field 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.

Example of a search that reads from one field and writes to another:

            "quantity": "quantity|item.quantity" 

          

Example of a search that only reads the value of the field:

            "status": "status#|" 

          

Nested Searches

You can use the results from one search in the filters of another search. The nested search runs first and returns an array of internal IDs. The outer search then uses these 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, searches in config only return up to 1000 results. If you set all: true, you can get more than 1000, but it might slow things down. If a search doesn’t return any results, config treats it as an empty array. Sometimes, this can cause errors. The default property makes sure you get a fallback value instead.

In the example below we can see a second search nested within 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. A default of 0 is set, to avoid any issues if zero results are found in the nested search. Any results that are found will be an array of internal IDs of assets and they will then be excluded from the broader search due to the search being nested 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