Image on subtable

If you want to display the image saved in another application on the kintone sub-table, there is a trick to force it.

Add a string (1 row) to the subtable.
Make sure to put the FileKey of the image in that field in JS.
At the time of display, the character string is converted to an image with the following code.
(function() {
  'use strict';
kintone.events.on([
    'app.record.detail.show',
], function(event) {
    let record = event.record;
    
    txt2image(record.Items.value);
    return event;
});  // end kintone.events.on [detail.show] 
    
// テキストフィールドをイメージに変更
let txt2image = (subTableValue)=>{
    setTimeout(()=>{
        let div_field = $('div.field-5684920');//←このNNNNNNNの部分は4の数字と書き換えるの
         //alert(div_field.length);
        for(let i=0 ; i < div_field.length ;i++){
           var FileKey = div_field[i].getElementsByTagName('span')[0].innerHTML;
           if ((FileKey !== "") && (FileKey !== undefined)){
            
            var img = document.createElement('img');
            var url = '/k/v1/file.json?fileKey=' + FileKey;
    
        //ファイルのダウンロード
          var xhr = new XMLHttpRequest();
          xhr.open('GET', url);
          xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
            xhr.send();     
          var im = document.createElement('img');
          im.style.width = "50px";
          im.setAttribute('src', url);            
            div_field.eq(i).replaceWith(im);
           }  
        }
    },1000) 
}  
})();

Leave a Reply