Query Examples for the Get Records API

Contents

Overview

This article introduces the basic query examples for the Get Records API.
Get Records API
Conditions can be set when retrieving the records by specifying the query string. The data can also be sorted, making it easier to organize.

Creating the Sample App

For better understanding, this article uses the following app to provide examples.

Adding the Help Desk Management App

Add the Help Desk Management App from the Kintone marketplace by following the tutorial on the Kintone Help Site:
Adding a sample app (External link)

Navigate to the Help Desk Management App and click the App settings icon (gear icon).

Add a Date field to the form for the Deadline. Then update the field name and field code for each field in the form to match the table below. Save the form when finished.

Field Type Field Name Field Code / Element ID
Text Organization Organization
Radio button Inquiry Type Inquiry_type
Date Deadline Deadline
Date and time Date and time (in the "Support History" table) Support_date

Creating the Sample Data

Create sample data for the query testing as follows. The fields not included in the chart below can be set to any sample data.

Organization Name Status Deadline Support_date
DEF Inc. Sage H Complete Feb 01, 2025 Jan 15, 2025 3:00 PM
ABC Corporation Jean C In progress Jan 01, 2025 Feb 07, 2025 5:00 PM

Sage H's record

Sample data in the All fields view

How to Write Query Strings

This section introduces how to write query strings and provides sample queries for using the Get Records API.

Format

A query is expressed in the following format.

1
"Field code"  "Operator"  "value / function"

For more detailed specifications of queries and the operators and functions that can be used for each field, refer to the following article:
Query string

A sample of retrieving records by specifying a query in JavaScript is introduced in the following section:
Using Variables in Queries

Next, the method and sample queries for each field will be introduced.

Text Field Value Specification (Single-line)

Exact match: When the value of the "Organization" fields is "ABC Corporation"

To specify text that exactly matches a specified value, use the = operator as follows:

1
Organization = "ABC Corporation"
Partial match: When the value of the "Organization" field contains "Corporation"

To specify text that partially matches a specified value, use the like operator as follows:

1
Organization like "Corporation"

To specify the value for a Drop-down field, use the in or not in operator as follows. When using the in or not in operator, the value must be enclosed in ().

1
Status in ("Not handled yet", "In progress")
1
Status not in ("Complete")

In addition, the following fields can also be retrieved using the in or not in operators:

  • Check box
  • Radio button
  • Multi-choice

Date Field Value Specification

When the value of the "Deadline" fields is "Feb 01, 2025"
1
Deadline = "2025-02-01"
When the value of the "Deadline" fields is from "Jan 01, 2025" to "Feb 01, 2025"

The following query retrieves records within a given date range. When specifying multiple conditions, use the and operator to link the expressions together.

1
Deadline >= "2025-01-01" and Deadline <= "2025-02-01"

Field in a Table's Value Specification

The = and != operators are generally used for the Date and Date and Time fields. However, they cannot be applied to tables.
Instead, use the in or not in operator.

When the value of the "Support_date" field is "Mar 27, 2025 3:00 PM"
1
Support_date in ("2025-03-27T15:00:00Z")

Multiple Fields and Conditions Specification

Multiple conditions can be specified using the and and or operators.

Specify multiple conditions using "and"
  • The value of Deadline field is earlier than Today.
  • The value of Status field does not include Complete.
1
Deadline < TODAY () and Status not in ("Complete")

The TODAY() function is one of the functions that can be used in queries.
These functions allow for easy specification of conditions such as TODAY(), LAST_WEEK() or NEXT_WEEK() without having to specify the date each time.
For more information on functions, refer to the following article:
Query Functions

Sort retrieved records using "order by"

Additionally, another condition can be added to the previous one.

  • The value of Deadline field is earlier than Today.
  • The value of Status field does not include Complete.
  • The Deadline field value is retrieved in ascending order.
1
Deadline < TODAY () and Status not in ("Complete") order by Deadline asc

In this way, order by option sorts the output records in ascending order.

Group Expressions

When specifying multiple conditions for multiple fields, group the expressions.
Expressions can be grouped by enclosing them in parentheses (). Grouping allows for the specification of more detailed conditions.

Specify conditions for grouping expressions

The value of the Inquiry Type field is Partnership or the value of the Deadline field is from 2025-01-01 to 2025-02-01.

1
(Inquiry_type in ("Partnership")) or (Deadline >= "2025-01-01" and LimitDay <= "2025-02-01")

Using Variables in Queries

When writing a query in JavaScript, there may be cases where including variables within the query is necessary.
For example, to use a value obtained from a record in a query, it is necessary to assign the value to a variable.

Consider the case in which it is necessary to retrieve other records that share the same Deadline value when a record is opened. To implement this condition, follow this specific order of processing:

  1. Retrieve the value of the opened record.
  2. Assign the retrieved value to a variable and use it in the query string.

The code is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(() => {
  'use strict';

  kintone.events.on('app.record.detail.show', (event) => {
    const record = event.record;
    const deadline = record.Deadline.value;
    const query = 'Deadline = "' + deadline + '"';

    const body = {
      app: kintone.app.getId(),
      query: query
    };

    kintone.api(kintone.api.url('/k/v1/records', true), 'GET', body, (resp) => {
      // success
      console.log(resp);
    }, (error) => {
      // error
      console.log(error);
    });
    return event;
  });
})();

On line 6, the value of the Deadline field is assigned to the deadline variable.
The deadline variable can now be used as a condition for record retrieval. Combine the conditions to create a query string as shown in line 7.