LoginSignup
1
0

More than 3 years have passed since last update.

kintoneの特定のフィールドをmdファイルとしてダウンロード

Last updated at Posted at 2019-08-30

kintoneの詳細画面とかにボタンを置いて、押すと任意のフィールドをmdファイルとしてダウンロード。
ダウンロードするファイル名はYYYY-MM-DD形式のフィールド(今回はルックアップ)の値を取得して、いい感じにトリミングして「YYYYMMDD.md」としてダウンロード

  • memo_markdownこの部分を任意のコピーしたいフィールドのフィールドコードに変更。
  • ファイル名につかう日付フィールド(今回はルックアップ)をrelease_dateというフィールドコードで配置
  • 「スペース」フィールドの配置が必要。今回はmd_link_sapceというフィールドコードで配置。
  • jQueryは読み込み必要。
sample.js
(function($) {
  'use strict';
  let events = [
    'app.record.detail.show'
  ]

  kintone.events.on(events, function(event){
    let el = kintone.app.record.getSpaceElement('md_link_sapce');
    $('<input />', {
      'type': 'button',
      'name': 'c_button',
      'value': 'Download',
      'class': 'create_button',
    }).on('click', function (resp) {
      var kin_stream = event.record.memo_markdown.value;
      var r_date = event.record.release_date.value;
      r_date = r_date.replace( /-/g , "" );
      SaveToFile(r_date + ".md",kin_stream);
    }).appendTo(el);
  });

  function SaveToFile(FileName,Stream) {
    if (window.navigator.msSaveBlob) {
      window.navigator.msSaveBlob(new Blob([Stream], { type: "text/markdown" }), FileName);
    } else {
      var a = document.createElement("a");
      a.href = URL.createObjectURL(new Blob([Stream], { type: "text/markdown" }));
      //a.target   = '_blank';
      a.download = FileName;
      document.body.appendChild(a) //  FireFox specification
      a.click();
      document.body.removeChild(a) //  FireFox specification
    }
  }

})(jQuery);
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0