Introduction
This is the second article of the cli-kintone series, focused on adding and deleting records using cli-kintone.
The previous tutorial can be found here: Export record data.
This article will continue to use the Customer Database used in the previous tutorial.
Add Records
STEP 1: Prepare a CSV file
The first step is to prepare a CSV file that will be used to add record data to the Kintone App.
It is not necessary to list every field in the App in the CSV file - the fields can be limited to those to add data to, as shown below:
Make sure to write the field code in the first row, and not the field name.
Save the data as customers.csv.
STEP 2: Add records by specifiying the CSV file
In addition to the authentication option, use the -f option to specify the file to import.
If customers.csv is saved in the same location as the cli-kintone executable file:
If the file path of customers.csv is specified:
If the file path of customers.csv is specified and imported from a specified line:
Add Records after Deleting Records
STEP 1: Add Records After Deleting all Records
Use the -f and -D options to delete all records before adding new records.
If no query is specified, all records in the App will be deleted before records are added.
STEP 2: Add Records After Deleting filtered records
To delete only specified records before adding new records, the records will need to be filtered for those to be deleted using the -q option. Refer to the Get Records article for information on how to write queries.
In the example below, the 5 latest records that have "Krispy" as the contact name are deleted before the new records are added:
STEP 3: Delete Records Without Adding Records
Records can be deleted without adding data by making an empty CSV file, specifying it with the -f option and then using the -D option:
To make an empty CSV file empty.csv on Windows:
For Mac and Linux, use one of the commands below in the terminal:
Add Records with Table data
In this example, the Expense Report App that was used in the previous tutorial is used again.
STEP 1: Create a CSV file containing table data
To add records that include table data, add an * symbol in the first column of the row that contains the field codes. Also add the * symbol to each row that contains the first table data row of tables in each record.
To avoid making mistakes, use a CSV file exported by cli-kintone as reference.
Save the contents above as tabledata.csv.
STEP 2: Add records by specifying the CSV file
Use the -f option to specify the CSV file to add records with table data.
The contents of the CSV file looks like the below when opened in Excel.
These are the screenshots of the three records that have data added to them. The data in the colored rectangles above match the data in the colored rectangles below.
CSV data for Check box and Multi-choice fields
Check box fields and Multi-choice fields are fields that can hold multiple values. A carriage return must be used to separate the multiple values for these fields. If the data is viewed in Excel, the multiple values can be seen on several lines inside one cell. When editing on excel, use the Alt + Enter shortcut in a cell for a carriage return.
The same goes for the tables. If the table contains these fields, separate the multiple values within these fields with carriage returns.
Example CSV data
The two records in the above images can be represented with the following CSV:
In Excel, this looks like the below:
Example CSV data for Tables
The two records in the above images can be represented with the following CSV:
In Excel, this looks like the below:
How to debug if records fail to be added
If any errors occur, check the logs that are outputted into the console.
The problem can also be identified by checking the requests on the Audit Log in the System Administration page.
Click the gear icon on the upper right menu of Kintone, and go to User & System Administration -> Audit Logs -> View & Download.
From the Audit Log list, it is possible to see what record operations were performed and their success/failure as well as the details of each operation by clicking the i mark on the left side of the table.
Looking at this information allows the user to see if requests from cli-kintone are successfully reaching their Kintone environment, and see what errors are the cause of any particular issue.
This is the end of Tutorial 2 for cli-kintone.
Hopefully this tutorial has solved any tricky issues involving managing table data and fields that can hold multiple values.