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.
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
The following sample code will display the value of the Updated datetime field in a Blank space field, by clicking a button.
Step 3. Field type and format
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.
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.
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().
Let's move to the next tutorials!