# テーブルのデータを別のアプリで取得する方法

**URL:** <https://community.cybozu.dev/t/topic/7626>\
**Category:** kintone 開発相談\
**Created:** [August 14, 2022, 2:29pm UTC](https://community.cybozu.dev/t/topic/7626 "2022-08-14T14:29:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2863](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Legacy\_Account2863](https://community.cybozu.dev/u/Legacy_Account2863)\
**Post date:** [August 14, 2022, 2:29pm UTC](https://community.cybozu.dev/t/topic/7626/1 "2022-08-14T14:29:42Z")

</div>

既出の質問と類似しているものと思いますが、解決方法がわからず困っています。

初心者向けのアドバイスお願いします。参考にしたページは[こちら](https://community.cybozu.dev/hc/ja/community/posts/900001007806-%E3%82%B5%E3%83%96%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%82%92%E5%88%A5%E3%82%A2%E3%83%97%E3%83%AA%E3%81%A7%E5%8F%96%E5%BE%97%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)。

**背景・実現したいこと**

アプリBのレコードを登録するときに、アプリAから成績書番号をキーに必要な情報（文字列1行、テーブルのデータ（複数あり））を転記させたい。

全部一度には考えられなかったので、コードはテーブル1つのデータ転記からチャレンジしましたが、そこすら出来ませんでした。

アプリA：アプリID→CTTIreport001

アプリAとBは転記させたい部分のフィールドの種類やフィールドコードは同じにしています。

**エラー情報** （開発者ツールのコンソール）

&nbsp;edit.js:123 Uncaught ReferenceError: CTTIreport001 is not defined

AのアプリID書くところに登録してあるアプリIDを書いているつもりなのですが、参照するものがありませんと出ているようで。。。なぜでしょうか？

**利用したソースコード**

(function() {  
&nbsp; &nbsp; “use strict”;

&nbsp; &nbsp; kintone.events.on([“app.record.edit.submit”, “app.record.create.submit”], function(e) {  
&nbsp; &nbsp; &nbsp; &nbsp; var record = e.record;  
&nbsp; &nbsp; &nbsp; &nbsp; var reportnumber = record[“成績書番号”].value;  
&nbsp; &nbsp; &nbsp; &nbsp; var formdetails1 = {};  
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; var body = {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘app’: CTTIreport001, // AのアプリID  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ‘query’: ‘成績書番号 = "’ + reportnumber + ‘"’  
&nbsp; &nbsp; &nbsp; &nbsp; };

&nbsp; &nbsp; &nbsp; &nbsp; return kintone.api(kintone.api.url(‘/k/v1/records’, true), ‘GET’, body).then(function(resp) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resp.records.forEach(function(record) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var TableA1 = record[“PAGE1”].value;  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (var t = 0; t \< Table.length; t++) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var Length1 = Table[t].value[“LENGH\_OF\_JIB1”].value;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var Radius1 = Table[t].value[“RADIUS1”].value;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var Angle1 = Table[t].value[“ANGLE1”].value;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var Test1 = Table[t].value[“TEST\_LOAD1”].value;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var Safe1 = Table[t].value[“SAFE\_WORKING\_LOAD”].value;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fomdetails1[Length1] = {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “LENGH\_OF\_JIB1”: Length1,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “RADIUS1”: Radius1,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “ANGLE1”: Angle1,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “TEST\_LOAD1”: Test1,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “SAFE\_WORKING\_LOAD”: Safe1  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return setData();  
&nbsp; &nbsp; &nbsp; &nbsp; });  
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; &nbsp; &nbsp; function setData() {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var TableB1 = record[“PAGE1”].value;  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var index = TableB.length - 1;  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; // テーブル初期化  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i \<= index; i++) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TableB1.splice(0, 1);  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp;&nbsp;  
&nbsp; &nbsp; // 取得したデータを追加  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (var key in fomdetails1) {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TableB1.push({  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “LENGH\_OF\_JIB1”: {value: fomdetails1[key][“LENGH\_OF\_JIB1”], type: “SINGLE\_LINE\_TEXT”},  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “RADIUS1”: {value: fomdetails1[key][“RADIUS1”], type: “SINGLE\_LINE\_TEXT”},  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “ANGLE1”: {value: fomdetails1[key][“ANGLE1”], type: “SINGLE\_LINE\_TEXT”},  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “TEST\_LOAD1”: {value: fomdetails1[key][“TEST\_LOAD1”], type: “SINGLE\_LINE\_TEXT”},  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “SAFE\_WORKING\_LOAD”: {value: fomdetails1[key][“SAFE\_WORKING\_LOAD”], type: “SINGLE\_LINE\_TEXT”}  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return e;  
&nbsp; &nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp; });  
})();

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1177](https://avatars.discourse-cdn.com/v4/letter/l/77aa72/32.png) [@Legacy\_Account1177](https://community.cybozu.dev/u/Legacy_Account1177)\
**Post date:** [August 15, 2022, 12:02am UTC](https://community.cybozu.dev/t/topic/7626/2 "2022-08-15T00:02:14Z")

</div>

エラーの出ている部分のみの回答になりますが、アプリIDは通常数字です。  
アプリを開いた時に「https://{サブドメイン}.cybozu.com/k/xxx/」のxxxの部分がアプリIDです。

他の確認方法として、アプリを開いている状態で開発者ツール等から

```
kintone.app.getId();

```

| &nbsp; |  
|  
| |

を実行すればアプリIDを取得できます。

ただ、エラーの原因そのものは、アプリIDとしている「CTTIreport001」が変数になっているためです（文字列として扱う場合はシングルクォートまたはダブルクォートで囲む必要があります）。この辺りはkintoneではなくJavaScriptの決まりなので、そちらをお調べ下さい。

同じエラーを出さないようにするためには

```
var body = {
app: 'CTTIreport001'

```

と記載するか、

```
var CTTIreport001 = 'CTTIreport001';

var body = {
app: CTTIreport001

```

と記載する必要があります（例として出しているだけで、使用できないコードです）。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2863](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Legacy\_Account2863](https://community.cybozu.dev/u/Legacy_Account2863)\
**Post date:** [August 15, 2022, 1:17pm UTC](https://community.cybozu.dev/t/topic/7626/3 "2022-08-15T13:17:27Z")

</div>

mis-hashimoto様

コメントありがとうございます。

早速確認してみます。

基礎知識不足ですが、もっと勉強していきます。ありがとうございました。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2863](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Legacy\_Account2863](https://community.cybozu.dev/u/Legacy_Account2863)\
**Post date:** [August 16, 2022, 11:22am UTC](https://community.cybozu.dev/t/topic/7626/4 "2022-08-16T11:22:36Z")

</div>

mis-hashimoto様

その後、細かいスペルミス等を修正したところ、無事に5つのテーブルのコピーに成功しました！

本当にありがとうございました！！

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/cybozu/original/1X/d5c841c3c5a6cb66eed514001c1b45147c9e1f4f.png) [@system](https://community.cybozu.dev/u/system)\
**Post date:** [September 4, 2024, 5:41am UTC](https://community.cybozu.dev/t/topic/7626/5 "2024-09-04T05:41:13Z")

</div>

Closed on September 4, 2024, 5:41am UTC

このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。
