(function () { 'use strict'; kintone.events.on('app.record.index.show', function (event) { var url = '{URL}'; var krewdataAppUrl = '{KREWDATA_APP_URL}'; var serialNumber = '{SERIAL_NUMBER}'; // ご利用の環境に合わせて上記の {URL}、{KREWDATA_APP_URL}、{SERIAL_NUMBER} に値を設定してください。 // {URL} :実行単位のURL // {KREWDATA_APP_URL} :krewData専用アプリのURL // {SERIAL_NUMBER} :リアルタイム実行プランのシリアルナンバー // (設定例) // var url = 'https://api.krewdata.grapecity.com/trigger/v1/abcdefghijklmn'; // var krewdataAppUrl = 'https://yourdomain.cybozu.com/k/123'; // var serialNumber = 'abcdef-jklmno-pqrstu-xyz123-456789'; // 一覧画面に「エクスポート」ボタンを配置 if (document.getElementById('export_button') !== null) { return; } var exportButton = document.createElement('button'); exportButton.id = 'export_button'; exportButton.innerText = 'フロー実行'; // ボタンクリック時の処理 exportButton.onclick = async(butotnEvent) => { if (window.confirm('krewDataのデータ編集フローを実行しますか?')) { // Request Access Token var tokenBody = { 'krewdataAppUrl': krewdataAppUrl, 'serialNumber': window.btoa(serialNumber) }; var tokenResponse = await sendRequest('token', url, tokenBody); console.log(JSON.stringify(tokenResponse)); // Run Execution Unit if (tokenResponse.code == 200) { var accessToken = tokenResponse.accessToken; var runBody = { 'accessToken': accessToken, 'user': kintone.getLoginUser().code, 'appId': event.appId.toString() }; var runResponse = await sendRequest('run', url, runBody); console.log(JSON.stringify(runResponse)); // Check Status if (runResponse.code == 200) { var taskId = runResponse.taskId; var statusBody = { 'accessToken': accessToken, 'taskId': taskId }; var statusInterval = setInterval(async function () { var statusResponse = await sendRequest('status', url, statusBody); console.log(JSON.stringify(statusResponse)); if (statusResponse.taskStatus == 'Success' || statusResponse.taskStatus == 'Failure') { clearInterval(statusInterval); } }, 5000); // 5sec } } } } kintone.app.getHeaderMenuSpaceElement().appendChild(exportButton); }); })(); function sendRequest(api, url, body) { var _kintone = kintone; var uri = url + '/' + api; return new _kintone.Promise(function (resolve, reject) { _kintone.proxy(uri, 'POST', { 'Content-Type': 'application/json;charset=UTF-8' }, body, function (body, status, headers) { resolve(JSON.parse(body)); }, function (error) { reject(error); }); }); }