# 新規作成時に、テーブルに自動で特定のデフォルト値で2行データをセットしたい

**URL:** https://community.cybozu.dev/t/topic/5179
**Category:** kintone 開発相談
**Created:** [2021 年 8 月 13 日午前 8:34 UTC](https://community.cybozu.dev/t/topic/5179 "2021-08-13T08:34:22Z")
**Posts on this page:** 3
**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: [2021 年 8 月 13 日午前 8:34 UTC](https://community.cybozu.dev/t/topic/5179/1 "2021-08-13T08:34:22Z")

</div>

申請の新規作成時に、テーブルに自動で2行データをセットしたいです。

テーブルの詳細は以下の通りです。3列目にはデータはセットしないです。

テーブルのフィールドコード：cs\_SendList

テーブルの1列目  
&nbsp; フィールド名：名前、型：文字列（１行）、フィールドコード：cs\_SendList\_Name

テーブルの2列目  
フィールド名：メアド、型：リンク、フィールドコード：cs\_SendList\_Mail

テーブルの3列目  
フィールド名：アクセスコード、型：文字列（１行）、フィールドコード：cs\_SendList\_Pass

1行セットする場合は、以下で行けたのですが、  
2行目に、Bさん、bbb@◯◯.co.jp をセットする場合、どのようにしたら良いでしょうか？  
3行目は空欄のままにしたいです。

&nbsp;

(function() {  
“use strict”;

var events1 = [“app.record.create.show”];

kintone.events.on(events1, function(event){  
var record = event.record;  
record.cs\_SendList.value[0].value[‘cs\_SendList\_Name’].value = ‘Aさん’;  
&nbsp; &nbsp; record.cs\_SendList.value[0].value[‘cs\_SendList\_Mail’].value = ‘aaa@~~.co.jp’;

return event;

});

})();

&nbsp;

&nbsp;

---

<div class="post-metadata">

### Author: ![Legacy\_Account1018](https://avatars.discourse-cdn.com/v4/letter/l/e56c9b/32.png) [@Legacy\_Account1018](https://community.cybozu.dev/u/Legacy_Account1018)
#### Post date: [2021 年 8 月 13 日午前 11:31 UTC](https://community.cybozu.dev/t/topic/5179/2 "2021-08-13T11:31:16Z")

</div>

こちらの記事の「行追加処理」のプログラムを参考にされると上手くいくと思います。  
[https://developer.cybozu.io/hc/ja/articles/360022502911-kintone%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E6%93%8D%E4%BD%9C%E3%81%AE%E5%9F%BA%E6%9C%AC-%E8%A1%8C%E3%81%AE%E8%BF%BD%E5%8A%A0-%E6%9B%B4%E6%96%B0-%E5%89%8A%E9%99%A4-](https://developer.cybozu.io/hc/ja/articles/360022502911-kintone%E3%81%AB%E3%81%8A%E3%81%91%E3%82%8B%E3%83%86%E3%83%BC%E3%83%96%E3%83%AB%E6%93%8D%E4%BD%9C%E3%81%AE%E5%9F%BA%E6%9C%AC-%E8%A1%8C%E3%81%AE%E8%BF%BD%E5%8A%A0-%E6%9B%B4%E6%96%B0-%E5%89%8A%E9%99%A4-)

空欄のままにしたい場合は値を「‘’」にします。

---

<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: [2021 年 8 月 13 日午後 2:37 UTC](https://community.cybozu.dev/t/topic/5179/3 "2021-08-13T14:37:06Z")

</div>

たねまき様

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

以下のように実装してうまく動きました！！

(function() {  
“use strict”;

var events1 = [“app.record.create.show”];

kintone.events.on(events1, function(event){  
var record = event.record;  
record.cs\_SendList.value[0].value[‘cs\_SendList\_Name’].value = ‘Aさん’;  
&nbsp; &nbsp; record.cs\_SendList.value[0].value[‘cs\_SendList\_Mail’].value = ‘aaa@~~.co.jp’;

const addName = ‘Bさん’;  
&nbsp; &nbsp; const addMail = ‘bbb@~~.co.jp’;

&nbsp; &nbsp; record.cs\_SendList.value.push({  
&nbsp; &nbsp; &nbsp; value: {  
&nbsp; &nbsp; &nbsp; &nbsp; “cs\_SendList\_Name”: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value: addName,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: ‘SINGLE\_LINE\_TEXT’,  
&nbsp; &nbsp; &nbsp; &nbsp; },  
&nbsp; &nbsp; &nbsp; &nbsp;“cs\_SendList\_Mail”: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value: addMail,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: ‘LINK’,  
&nbsp; &nbsp; &nbsp; &nbsp;},  
&nbsp; &nbsp; &nbsp; &nbsp;“cs\_SendList\_Pass”: {  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;value: ‘’,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;type: ‘SINGLE\_LINE\_TEXT’,  
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}  
&nbsp; &nbsp; &nbsp; }  
&nbsp; &nbsp;});

return event;

});

})();
