Retrieve Record Data (Record Details)

Introduction

This tutorial will teach how to retrieve values from a record from the Kintone record details page.

Step 1. Retrieve Record ID value

The first step is to retrieve the record ID of the current record - this time initiated by a button click. Record IDs are the key IDs for each record in an App, starting from 1. Use the kintone.app.record.getId() function to retrieve the Record ID. Check the Get Record article for more details of the API.
Below is a sample code for retrieving and displaying the Record ID.

Save the code as a JavaScript file, and upload it to the JavaScript and CSS settings of App. Refer to the Customizing Kintone with JavaScript & CSS article from the Kintone Help Center for more details on adding JavaScript files to a Kintone App.
A button should appear on the record details page. Click it to retrieve and display the record ID of the current record.

 

Step 2. Retrieve record value

The function to retrieve record values from the desktop is kintone.app.record.get(). For mobile, kintone.mobile.app.record.get() is used instead.
The returned value will be in a JSON format, and null will be returned in case of errors.

A sample code can be written as follows:

 

You will need to replace field_code with the field code of the field to retrieve the value from. Field codes can be checked and updated from the App settings menu.
Navigate through to Edit Form > (Hover over a field already set in the canvas) > Settings > Field Code

 

after01.png

 

 

The following sample code will display the value of the Updated datetime field in a Blank space field, by clicking a button.

In addition to uploading the above JavaScript to the JavaScript an CSS settings, place a Blank space field into the App form, and name the Element ID, my_space_field from the Blank space field settings. The Add Buttons (Record Details) tutorial shows how to set Blank space field settings.

Note: There are several ways to write JavaScript code to retrieve values from the returned object. Use the below code as reference.

Step 3. Field type and format

After applying the JavaScript code, and clicking on the button on the record details page, check the value that is displayed on the Blank space field.

 

 

Notice that the date formats in the Blank space field and the Updated datetime field are different.
Check the Field Types and Date Formats pages as formats of data displayed on HTML and data retrieved by API may look different.

Step 4. Be careful when using kintone.app.record.get()

Check the notes written about the kintone.app.record.get() API.

 

Screen_Shot_2019-04-18_at_5.41.35_PM.png

 

Due to this, the following code will be incorrect, and will not work.

Step 5. The event object

The previous samples returns an Event object.

 

after02.png

 

To understand the event object more, check back on the Record Details Event page.
The property information of the event object is listed in the page.

 

 

Notice that the event object already has the same return value as the values obtained with kintone.app.record.get().

Step 6. Retrieving record values from the event object

The below sample will retrieve the value of the Updated datetime field from the event object instead of using kintone.app.record.get().

Finally

We hope you enjoyed learning how to retrieve record data by the Kintone JavaScript API and have a good understanding of the event object.
Let's move to the next tutorials!

Was this article helpful?
1 out of 1 found this helpful
Do you have any questions or issues related to this article?
Please share your views with us in the Community forums!