0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GAS~kintone連携

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)
  }
}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?