const appId = "100";
const apiToken = "---";
const subdomain = "---";
const book = SpreadsheetApp.openByUrl(
'https://docs.google.com/spreadsheets/d/xxxxxx/edit?gid=0#gid=0'
);
const FLAG = 4
function myFunction() {
const sheet = book.getSheets()[0];
const data = sheet.getDataRange().getValues();
data.splice(0, 1);
for (let i = 0; i < data.length; i++) {
const row = data[i];
if (row[FLAG] == 1) {
continue;
}
console.log(row[2]);
addKintoneRecord(row);
//ヘッダは抜いている。
const cell = sheet.getRange((i + 2), (FLAG + 1));
console.log(row[0])
// console.log(cell.getValue());
cell.setValue(1);
}
}
function addKintoneRecord(row) {
const url = `https://${subdomain}.cybozu.com/k/v1/record.json`;
// Replace with the data you want to add to the Kintone app
const recordData = {
"文字列__1行_": { value: row[1] },
};
const payload = {
app: appId,
record: recordData
};
const options = {
method: "post",
headers: {
"X-Cybozu-API-Token": apiToken,
"Content-Type": "application/json"
},
payload: JSON.stringify(payload)
};
try {
const response = UrlFetchApp.fetch(url, options);
const result = JSON.parse(response.getContentText());
Logger.log("Record Added: %s", result);
} catch (e) {
Logger.log(e.stack)
}
}