kintone.Promise を使用する(非推奨)

目次

cybozu.comがサポートしているすべてのWebブラウザーで、 ブラウザーの Promise (External link) を利用可能です。
kintone.Promiseは使わず、ブラウザーのPromiseを使うことを推奨します。

kintone.Promise を使用する

kintone.Promiseとは、Promiseオブジェクトを使ったkintone JavaScript APIです。
kintone.Promiseを利用すると、Internet Explorer 11などのPromiseに対応していないブラウザーでもPromiseを扱うことができます。

関数

kintone.Promise(executor)

引数

パラメーター名 必須 説明
executor 関数 必須 Promise オブジェクトに渡す、非同期処理の関数
executor の引数には、次の 2 つの関数が渡されます。
  • resolve:executor 内で、処理に成功したときに呼び出す関数
    resolve 関数に渡した値は、then メソッドの第 1 引数で受け取ることができます。
  • reject:executor 内で、処理に失敗したときに呼び出す関数
    reject 関数に渡した値は、then メソッドの第 2 引数または catch メソッドで受け取ることができます。

thenメソッド、catchメソッドの仕様は MDN Web Docs | Promise (External link) に従います。

戻り値

kintone.Promiseオブジェクト

対応イベント

レコード一覧イベント
レコード詳細イベント
レコード追加イベント
レコード編集イベント
レコード印刷画面イベント
グラフイベント
ポータル表示イベント

サンプルコード

kintone REST API リクエストを送信する APIを使ったリクエストの場合
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
const body = {
  app: 1,
  id: 1
};

kintone.events.on('app.record.create.submit', (event) => {
  const record = event.record;
  return new kintone.Promise((resolve, reject) => {
    kintone.api(kintone.api.url('/k/v1/record.json', true), 'GET', body).then((resp) => {
      record['文字列_1'].value = resp.record['文字列_1'].value;
      resolve(event);
    });
  });
});
kintone REST API リクエストを送信する APIを使わないリクエストの場合
1
2
3
4
5
6
7
8
9
kintone.events.on('app.record.create.submit', (event) => {
  const record = event.record;
  return new kintone.Promise((resolve, reject) => {
    setTimeout(() => {
      record['文字列_1'].value = 'sample';
      resolve(event);
    }, 10000);
  });
});