# REST API GETを全体JSでメニューバーにレコード件数を

**URL:** <https://community.cybozu.dev/t/topic/4108>\
**Category:** kintone 開発相談\
**Created:** [June 18, 2019, 8:33am UTC](https://community.cybozu.dev/t/topic/4108 "2019-06-18T08:33:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account762](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@Legacy\_Account762](https://community.cybozu.dev/u/Legacy_Account762)\
**Post date:** [June 18, 2019, 8:33am UTC](https://community.cybozu.dev/t/topic/4108/1 "2019-06-18T08:33:33Z")

</div>

失礼します。

以下の画像の部分に固定のアプリのレコード数を表記したいと考えています。

ほぼ、全ての画面で対応したいので、全体JSで行いたいと思います。

以下のようなものを作成しました。

&nbsp;

//全件取得

function fetchRecords(opt\_offset, opt\_limit, opt\_records) {  
var offset = opt\_offset || 0;  
var limit = opt\_limit || 500;  
var allRecords = opt\_records || [];  
var params = {app: (取得したいアプリID), query: ‘order by $id asc limit ’ + limit + ’ offset ’ + offset};  
return kintone.api(’/k/v1/records’, ‘GET’, params).then(function(resp) {  
allRecords = allRecords.concat(resp.records);  
if (resp.records.length === limit) {  
return fetchRecords(offset + limit, limit, allRecords);  
}  
return allRecords;  
});  
}

(function(){  
“use strict”;  
$().ready(function() {  
setTimeout(function(){

//メニューバー取得

var leftmenu = document.getElementsByClassName(“gaia-header-toolbar-left”)[0].childNodes[0].childNodes[0];

var tuika = document.createElement(“li”);  
var ti = document.createElement(“p”);

&nbsp;

fetchRecords(kintone.app.getId()).then(function(records) {

var recordti = 0;  
for(var T=0; T\<records.length; T++){  
recordti = recordti +1;

}  
ti.innerHTML = recordti ;

})

tuika.appendChild(ti);  
leftmenu.appendChild(tuika);

},1000);  
});  
return event;  
})();

&nbsp;

ポータルと、スペースでは問題なく機能するのですが、

各アプリの表示時は、repsの中身が0になります。

エラーにはならず、発火もしています。

どなたか、ご教授お願いします。

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1740](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@Legacy\_Account1740](https://community.cybozu.dev/u/Legacy_Account1740)\
**Post date:** [June 19, 2019, 2:21am UTC](https://community.cybozu.dev/t/topic/4108/2 "2019-06-19T02:21:41Z")

</div>

鶴見様

お世話になっております．  
cstapの江田です．

fetchRecords()を呼ぶ際の引数を除去すればよいと思います．

```
fetchRecords().then(function(records) {

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account762](https://avatars.discourse-cdn.com/v4/letter/l/fbc32d/32.png) [@Legacy\_Account762](https://community.cybozu.dev/u/Legacy_Account762)\
**Post date:** [June 20, 2019, 5:09am UTC](https://community.cybozu.dev/t/topic/4108/3 "2019-06-20T05:09:07Z")

</div>

あっ。

本当ですね。

何故気づかなかったかってぐらい単純な理由ですね。

ありがとうございます。

たすかりました。
