selectOptions Operation
Using the selectOptions operations in REST web services, you can retrieve valid select options for specific records and fields.
This is useful if you are writing an application UI that needs to mimic NetSuite UI logic, if the referenced record type is not yet exposed. The selectOptions operation is also useful when the logged-in user's role does not have permission to the instances of the referenced record type. A call to the selectOptions operation can return different results for the same field for different roles.
You send a selectOptions request using the same URL structure as any other REST record service operation, but you must add an Accept request header and the list of requested fields in the fields= query parameter. The following examples show the basic structure of a selectOptions request.
The following request returns the select option values on a new record instance.
POST ../services/rest/record/v1/customer?fields=entitystatus
Accept: application/vnd.oracle.resource+json; type=select-options
The following request returns the select option values on an existing record instance.
PATCH ../services/rest/record/v1/customer/1?fields=entitystatus
Accept: application/vnd.oracle.resource+json; type=select-options
Sample Code
The select option values returned by the selectOptions operation can depend on the values of other field values on a record. The request body can be empty, or it can include field values for fields that the select option values depend on.
In the following example, a request for select option values is sent for the dueToFromSubsidiary field on the line sublist. The value depends on the value of the subsidiary field and the values of the subsidiary and eliminate fields on the line sublist.
POST ../services/rest/record/v1/advInterCompanyJournalEntry?fields=line.dueToFromSubsidiary
Accept: application/vnd.oracle.resource+json; type=select-options
{
"subsidiary": {
"id": 1
},
"line": {
"items": [
{
"subsidiary": {
"id": 1
},
"eliminate": true
}
]
}
}
The response contains the select option values for all fields in the fields= query parameter.
Content-Type: application/vnd.oracle.resource+json; type=select-options
{
"links": [
{
"rel": "self",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=entitystatus"
}
],
"entitystatus": {
"_selectOptions": {
"links": [
{
"rel": "self",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=entitystatus"
}
],
"items": [
{
"id": 16,
"refName": "CUSTOMER-Lost Customer"
},
{
"id": 13,
"refName": "CUSTOMER-Closed Won"
},
{
"id": 15,
"refName": "CUSTOMER-Renewal"
}
],
"count": 3,
"offset": 0,
"hasMore": false,
"totalResults": 3
}
}
}
Returning the Select Option Values of Multiple Fields
Using the selectOptions operation, you can also return the select option values for multiple fields in a single request. You must specify the fields in the fields= query parameter, separated by a comma. The following example shows a response to a request for select option values on multiple fields.
{
"links": [
{
"rel": "self",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=entitystatus,location"
}
],
"entitystatus": {
"_selectOptions": {
"links": [
...
],
"items": [
...
],
"count": 3,
"offset": 0,
"hasMore": false,
"totalResults": 3
}
},
"location": {
"_selectOptions": {
"links": [
...
],
"items": [
...
],
"count": 100,
"offset": 0,
"hasMore": true,
"totalResults": 103
}
}
}
Filtering Select Values
To filter a long list of select values, you can use the q= query parameter to specify filter conditions. You can use the CONTAIN, IS, and START_WITH query operators. Filtering applies to refName values in the REST response, not to IDs. You can filter multiple fields in a single request by using a comma. The following example shows how to filter multiple fields.
For general information about filtering, see Record Collection Filtering.
POST ../services/rest/record/v1/customer?fields=entitystatus,location&q=entitystatus START_WITH LEAD-, location IS "United States"
Accept: application/vnd.oracle.resource+json; type=select-options
Paginating Select Values
You can use the limit= and offset= query parameters to specify the page size and the number of results you want to return on a single page.
Every selected field returns its own properties of count, offset, hasMore, totalResults. Paging is shared for all selected fields, but every field has its own paging link in the request body.
The following example shows a REST response with limit= and offset= query parameters specified. For more information about using paging, see Collection Paging.
{
"links": [
{
"rel": "self",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=entitystatus,location&limit=50&offset=0"
}
],
"entitystatus": {
"_selectOptions": {
"links": [
{
"rel": "self",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=entitystatus&limit=50&offset=0"
}
],
"items": [
...
],
"count": 3,
"offset": 0,
"hasMore": false,
"totalResults": 3
}
},
"location": {
"_selectOptions": {
"links": [
{
"rel": "next",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=location&limit=50&offset=50"
},
{
"rel": "last",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=location&limit=50&offset=100"
},
{
"rel": "self",
"method": "POST",
"mediaType": "application/vnd.oracle.resource+json; type=select-options",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/customer?fields=location&limit=50&offset=0"
}
],
"items": [
...
],
"count": 50,
"offset": 0,
"hasMore": true,
"totalResults": 103
}
}
}