# CSV出力　カスタマイズ（フォームの項目の結合）

**URL:** <https://community.cybozu.dev/t/topic/7229>\
**Category:** kintone 開発相談\
**Created:** [2020 年 11 月 12 日午後 1:52 UTC](https://community.cybozu.dev/t/topic/7229 "2020-11-12T13:52:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2354](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@Legacy\_Account2354](https://community.cybozu.dev/u/Legacy_Account2354)\
**Post date:** [2020 年 11 月 12 日午後 1:52 UTC](https://community.cybozu.dev/t/topic/7229/1 "2020-11-12T13:52:08Z")

</div>

作成したアプリで、一覧でデータを見たときに、

伝票番号（自動入力）、人数（数値）、内訳（文字列）、〜〜〜、〜〜〜、

↑のように列があるときに、

CSV出力で、

この列と別で、伝票番号\_人数\_内訳 という上の3つをアンダーバーで結合した列をデフォルトである上記の列に加えて、1列、別で出力したいのですが、可能でしょうか？

人数と内訳だけであれば、元々のフォームに計算式で、人数\_内訳 と項目を作っておけばいいかなと思うのですが、伝票番号は保存時に自動入力なので、それだとできないのでは？と思いました。

何かいい方法があれば教えていただきたいです。

よろしくお願いします

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1377](https://avatars.discourse-cdn.com/v4/letter/l/e495f1/32.png) [@Legacy\_Account1377](https://community.cybozu.dev/u/Legacy_Account1377)\
**Post date:** [2020 年 11 月 13 日午前 2:17 UTC](https://community.cybozu.dev/t/topic/7229/2 "2020-11-13T02:17:49Z")

</div>

fukuyama さん

外れましたら申し訳ございません。

試していないですが、  
新規レコード保存成功後イベントapp.record.create.submit.successのハンドラ内で、  
kintone.api(pathOrUrl, PUT, params)&nbsp;を使って、保存したレコードを更新する手はあるかと思います。  
つまり、保存成功したレコードのオブジェクトを受け取り、結合しようとするフィールドの値を取り出して、  
結合した文字列を表示するフィールドにセットします。

また、レコード編集の際に、app.record.edit.change.\<フィールドコード\>を使って、  
結合対象フィールドの値が変更されたら、結合した文字列を更新します。

文字列結合のカスタマイズは次の記事が参考になるかと思います。

[タイトルに「名前＋日付」を結合してみよう！](https://community.cybozu.dev/hc/ja/articles/200880864)

[文字結合プラグイン](https://community.cybozu.dev/hc/ja/articles/208797666)

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2354](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@Legacy\_Account2354](https://community.cybozu.dev/u/Legacy_Account2354)\
**Post date:** [2020 年 11 月 16 日午前 5:56 UTC](https://community.cybozu.dev/t/topic/7229/3 "2020-11-16T05:56:51Z")

</div>

[akika](https://community.cybozu.dev/hc/ja/profiles/392470796892-akika)様

教えてくださりありがとうございます。

以下のように実装してみたのですが、うまくいかないので、どのように実装すれば更新できるか教えていただけないでしょうか？

質問時には、詳細をお伝えできていなかったのですが、更新したい場所がテーブル内の項目になります。

（以下の名称は全てフィールドコードです）

具体的には、

「テーブル」の中身の1つのフィールドコード「CSJS100」をテーブルの中身の項目である「内訳」\_「参加人数」\_「伝票番号」に更新したいです。

&nbsp;

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

&nbsp; kintone.events.on(‘app.record.create.submit.success’, function(event){  
&nbsp; var recordId = event.recordId;&nbsp;  
&nbsp; var i = 0;  
&nbsp; var CSJS100 = ‘CSJS100’;  
&nbsp; event.record.テーブル.value.forEach(function(val){  
&nbsp; &nbsp; &nbsp;val.value.CSJS100.value = val.value.内訳.value + ‘\_’ + val.value.参加人数.value + ‘\_’ + recordId;

&nbsp; &nbsp; &nbsp;//&nbsp; ↓以下で、CSJS100に入れたいデータは取得できています。  
&nbsp; &nbsp; &nbsp;console.log(val.value.CSJS100.value);

&nbsp; &nbsp; //レコードの更新API  
&nbsp; &nbsp; var body = {  
&nbsp; &nbsp; &nbsp; &nbsp;“app”: 8,  
&nbsp; &nbsp; &nbsp; &nbsp;“id”: recordId,  
&nbsp; &nbsp; &nbsp; &nbsp;“record”: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;“テーブル”: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “value” : [  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “id”: i,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;“value”: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “CSJS100”:{  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; “value”: val.value.CSJS100.value  
}  
&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 kintone.api(kintone.api.url(‘/k/v1/record’,true), ‘PUT’, body).then(function(resp){  
return event;  
});

})

})

})();

&nbsp;

実際に上記のコードで実行すると、

エラーが出てしまい、テーブルの他の必須項目が入ってないです、というようなエラー内容が出ます。

テーブル内の「CSJS100」の項目のみ更新したいので、他の項目は更新したくないのですが、何かやり方が間違っていますでしょうか？

またもっと簡単なやり方があれば教えていただけますと幸いです。

よろしくお願いします。

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2354](https://avatars.discourse-cdn.com/v4/letter/l/858c86/32.png) [@Legacy\_Account2354](https://community.cybozu.dev/u/Legacy_Account2354)\
**Post date:** [2020 年 11 月 17 日午前 8:28 UTC](https://community.cybozu.dev/t/topic/7229/4 "2020-11-17T08:28:04Z")

</div>

すみません、デフォルトで、2項目のフィールドと\_2つは繋げておいて、伝票番号だけを追加するやり方で進めました。

続きの質問は、こちらに記載させていただきました。

[https://developer.cybozu.io/hc/ja/community/posts/900002697443-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E7%99%BB%E9%8C%B2%E6%99%82%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA-%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E5%86%85%E3%81%AE%E3%81%82%E3%82%8B%E9%A0%85%E7%9B%AE%E3%81%AB%E4%BC%9D%E7%A5%A8%E7%95%AA%E5%8F%B7%E3%82%92%E8%BF%BD%E8%A8%98%E3%81%97%E3%81%A6%E4%BF%9D%E5%AD%98%E3%81%99%E3%82%8B](https://developer.cybozu.io/hc/ja/community/posts/900002697443-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E7%99%BB%E9%8C%B2%E6%99%82%E3%81%AE%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA-%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E5%86%85%E3%81%AE%E3%81%82%E3%82%8B%E9%A0%85%E7%9B%AE%E3%81%AB%E4%BC%9D%E7%A5%A8%E7%95%AA%E5%8F%B7%E3%82%92%E8%BF%BD%E8%A8%98%E3%81%97%E3%81%A6%E4%BF%9D%E5%AD%98%E3%81%99%E3%82%8B)

よろしくお願いします。
