# ワンクリックで一括承認と同時に詳細画面に配置した別のボタン押したい。

**URL:** <https://community.cybozu.dev/t/topic/6056>\
**Category:** kintone 開発相談\
**Created:** [June 11, 2022, 12:15pm UTC](https://community.cybozu.dev/t/topic/6056 "2022-06-11T12:15:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account1923](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@Legacy\_Account1923](https://community.cybozu.dev/u/Legacy_Account1923)\
**Post date:** [June 11, 2022, 12:15pm UTC](https://community.cybozu.dev/t/topic/6056/1 "2022-06-11T12:15:35Z")

</div>

[https://developer.cybozu.io/hc/ja/articles/211583223-%E3%83%AF%E3%83%B3%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%A7%E4%B8%80%E6%8B%AC%E6%89%BF%E8%AA%8D%E3%82%92%E3%81%97%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86](https://community.cybozu.dev/hc/ja/community/posts/900001371646-%E3%83%AF%E3%83%B3%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%A7%E6%89%BF%E8%AA%8D-%E3%82%AB%E3%82%B9%E3%82%BF%E3%83%9E%E3%82%A4%E3%82%BA?input_string=%E3%83%AF%E3%83%B3%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%A7%E6%89%BF%E8%AA%8D)

上記のサイトにて一覧別で一括承認が出来るようになったのですが、一括承認をするのと同時（又は承認する前に）別に詳細画面に配置したボタンを押すようにしたいのですが、下記コードのどの部分に何を追加すればいいか分からない為、ご教授頂きたいです。

（クリックしたいボタンのidは"twplus\_btn\_notify”です。）

| | /\* |  
| | \* ワンクリックで一括承認するプログラム |  
| | \* Copyright (c) 2016 Cybozu |  
| | \* |  
| | \* Licensed under the MIT License |  
| | \*/ |  
| | |  
| | (function() { |  
| | “use strict”; |  
| | kintone.events.on(“app.record.index.show”, function(event) { |  
| | var appId = kintone.app.getId(); |  
| | if (event.viewId !== ××××) { |  
| | return; |  
| | } |  
| | if ($(‘.header-contents’).length !== 0) { |  
| | return; |  
| | } |  
| | var el = kintone.app.getHeaderSpaceElement(); |  
| | var headerDiv = $(“\<div\>\</div\>”, { |  
| | class: “header-contents” |  
| | }); |  
| | //make a button for approval. |  
| | var balusButton = $(“\<button\>\</button\>”, { |  
| | class: “approval-button” |  
| | }). |  
| | html(“一括承認！”). |  
| | click(function() { |  
| | if (event.records.length \> 0) { |  
| | window.swal({ |  
| | title: “本当に全て承認して大丈夫ですか？”, |  
| | text: “表示されているレコードを全て承認します”, |  
| | type: “warning”, |  
| | showCancelButton: true, |  
| | confirmButtonColor: “#DD6B55”, |  
| | confirmButtonText: “承認！”, |  
| | cancelButtonText: “やっぱりやめる”, |  
| | closeOnConfirm: false }, |  
| | function() { |  
| | var records = []; |  
| | for (var h = 0; h \< event.records.length; h++) { |  
| | var obj = {}; |  
| | obj[“id”] = event.records[h].$id.value; |  
| | obj[“action”] = “承認”; //プロセス管理で設定されたアクション名を指定 |  
| | records.push(obj); |  
| | } |  
| | var requestObj = { |  
| | “app”: appId, |  
| | “records”: records |  
| | }; |  
| | kintone.api(kintone.api.url(“/k/v1/records/status”, true), “PUT”, requestObj, function() { |  
| | window.swal({title: “承認に成功しました！”, |  
| | text: “お疲れ様でした。”, |  
| | type: “success”}, function() { |  
| | location.reload(); |  
| | }); |  
| | }); |  
| | }); |  
| | } else { |  
| | window.swal({ |  
| | title: “申請中のレコードがありません”, |  
| | type: “warning”}); |  
| | } |  
| | }); |  
| | headerDiv.append(balusButton); |  
| | headerDiv.append($(“\<br /\>”)); |  
| | headerDiv.appendTo(el); |  
| | }); |  
| | })(); |

&nbsp;

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2613](https://avatars.discourse-cdn.com/v4/letter/l/41988e/32.png) [@Legacy\_Account2613](https://community.cybozu.dev/u/Legacy_Account2613)\
**Post date:** [June 11, 2022, 5:42pm UTC](https://community.cybozu.dev/t/topic/6056/2 "2022-06-11T17:42:39Z")

</div>

コードブロックを利用しましょう。

&nbsp;

```
/*

 * ワンクリックで一括承認するプログラム

* Copyright (c) 2016 Cybozu

 *

 * Licensed under the MIT License

 */

(function () {

  "use strict";

  kintone.events.on("app.record.index.show", function (event) {

    var appId = kintone.app.getId();

    if (event.viewId !== "××××") {

      return;

    }

    if ($(".header-contents").length !== 0) {

      return;

    }

    var el = kintone.app.getHeaderSpaceElement();

    var headerDiv = $("<div></div>", {

      class: "header-contents",

    });

    //make a button for approval.

    var balusButton = $("<button></button>", {

      class: "approval-button",

    })

      .html("一括承認！")

      .click(function () {

        if (event.records.length > 0) {

          window.swal(

            {

              title: "本当に全て承認して大丈夫ですか？",

              text: "表示されているレコードを全て承認します",

              type: "warning",

              showCancelButton: true,

              confirmButtonColor: "#DD6B55",

              confirmButtonText: "承認！",

              cancelButtonText: "やっぱりやめる",

              closeOnConfirm: false,

            },

            function () {

              var records = [];

              for (var h = 0; h < event.records.length; h++) {

                var obj = {};

                obj["id"] = event.records[h].$id.value;

                obj["action"] = "承認"; //プロセス管理で設定されたアクション名を指定

                records.push(obj);

              }

              var requestObj = {

                app: appId,

                records: records,

              };

              kintone.api(

                kintone.api.url("/k/v1/records/status", true),

                "PUT",

                requestObj,

                function () {

                  window.swal(

                    {

                      title: "承認に成功しました！",

                      text: "お疲れ様でした。",

                      type: "success",

                    },

                    function () {

                      location.reload();

                    }

                  );

                }

              );

            }

          );

        } else {

          window.swal({

            title: "申請中のレコードがありません",

            type: "warning",

          });

        }

      });

    headerDiv.append(balusButton);

    headerDiv.append($("<br />"));

    headerDiv.appendTo(el);

  });

})();

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1923](https://avatars.discourse-cdn.com/v4/letter/l/85e7bf/32.png) [@Legacy\_Account1923](https://community.cybozu.dev/u/Legacy_Account1923)\
**Post date:** [June 12, 2022, 2:36am UTC](https://community.cybozu.dev/t/topic/6056/3 "2022-06-12T02:36:59Z")

</div>

プログラミング初心者ですいません。  
ご指摘ありがとうございます！  
このコードに何を追加すれば宜しいでしょうか？
