かのこ様
お世話になっております。 cstapの江田と申します。
仰る通り、コードを少し変えて転用できます。
(function(){"use strict";varMyLookUp=(function(fieldSettings){functionMyLookUp(fieldSettings){this.fieldSettings=fieldSettings;}MyLookUp.prototype={createModal:function(){var\_this=this;this.modal=document.createElement('div');this.modalTable=document.createElement('table');this.modalTbody=document.createElement('tbody');this.modal.classList.add('lookUpModal');this.modalTable.classList.add('lookUpModalTable');this.modalTable.innerHTML=('\<thead\>\<tr\>'+this.fieldSettings.viewFields.reduce(function(columns,viewField){returncolumns+'\<th\>'+viewField+'\</th\>';},'')+'\<th\>取得\</th\>'+'\</tr\>\</thead\>');this.modal.addEventListener('click',function(e){if(e.target===\_this.modal){\_this.removeModal();}});this.modalTbody.addEventListener('click',function(e){if(e.target.classList.contains('modalGetButton')){\_this.copyDatas(\_this.records[e.target.getAttribute('data-index')]);}});this.modalTable.appendChild(this.modalTbody);this.modal.appendChild(this.modalTable);document.body.appendChild(this.modal);returnthis;},showModal:function(){var\_this=this;this.modalTbody.innerHTML=(\_this.records.reduce(function(rows,record,index){return(rows+'\<tr\>'+\_this.fieldSettings.viewFields.reduce(function(columns,viewField){returncolumns+'\<td\>'+record[viewField].value+'\</td\>';},'')+'\<td\>\<a class="modalGetButton" data-index="'+index+'"\>取得\</a\>\</td\>'+'\</tr\>')},''));this.modal.classList.add('on');},removeModal:function(){this.modal.classList.remove('on');},createGetButton:function(){var\_this=this;this.getButton=document.createElement('a');this.getButton.innerHTML='取得';this.getButton.classList.add('lookUpButton');this.getButton.addEventListener('click',function(){varquery;\_this.event=kintone.app.record.get();if(\_this.event.record[\_this.fieldSettings.copyField.to].value){query=\_this.event.record[\_this.fieldSettings.copyFieldSelectField].value+'="'+\_this.event.record[\_this.fieldSettings.copyField.to].value+'"';if(\_this.fieldSettings.query)query+=(' and '+\_this.fieldSettings.query);}else{query=\_this.fieldSettings.query;}kintone.api(kintone.api.url('/k/v1/records',true),'GET',{app:\_this.fieldSettings.app,query:query+\_this.fieldSettings.sort}).then(function(response){if(!response.records.length){alert('データがありません。');}elseif(response.records.length===1){\_this.copyDatas(response.records[0]);}else{\_this.records=response.records;\_this.showModal(response.records);}});});returnthis;},createClearButton:function(){var\_this=this;this.clearButton=document.createElement('a');this.clearButton.classList.add('lookUpButton');this.clearButton.innerHTML='クリア';this.clearButton.addEventListener('click',function(){\_this.clearDatas();});returnthis.clearButton;},showButtons:function(){kintone.app.record.getSpaceElement(this.fieldSettings.buttonSpace).appendChild(this.getButton);kintone.app.record.getSpaceElement(this.fieldSettings.buttonSpace).appendChild(this.createClearButton());returnthis;},copyDatas:function(record){var\_this=this;this.event.record[this.fieldSettings.copyField.to].value=record[this.event.record[this.fieldSettings.copyFieldSelectField].value].value;this.fieldSettings.otherCopyFields.forEach(function(otherCopyField){\_this.event.record[otherCopyField.to].value=record[otherCopyField.from].value;});this.event.record[this.fieldSettings.recordIdField].value=record.レコード番号.value;kintone.app.record.set(this.event);this.removeModal();//alert('参照先からデータが取得されました。');},clearDatas:function(record){var\_this=this;this.event.record[this.fieldSettings.copyField.to].value=null;this.fieldSettings.otherCopyFields.forEach(function(otherCopyField){\_this.event.record[otherCopyField.to].value=null;});this.event.record[this.fieldSettings.recordIdField].value=null;kintone.app.record.set(this.event);},disableOtherCopyFields:function(event){this.fieldSettings.otherCopyFields.forEach(function(otherCopyField){event.record[otherCopyField.to].disabled=true;});event.record[this.fieldSettings.recordIdField].disabled=true;//kintone.app.record.setFieldShown(this.fieldSettings.recordIdField, false);returnevent;},createLink:function(event){kintone.app.record.getFieldElement(this.fieldSettings.copyField.to).innerHTML=('\<a href="../'+this.fieldSettings.app+'/show#record='+event.record[this.fieldSettings.recordIdField].value+'" target="\_blank"\>'+event.record[this.fieldSettings.copyField.to].value+'\</a\>');},createLinks:function(event){var\_this=this;event.records.forEach(function(record,index){kintone.app.getFieldElements(\_this.fieldSettings.copyField.to)[index].innerHTML=('\<div\>\<a href="../'+\_this.fieldSettings.app+'/show#record='+record[\_this.fieldSettings.recordIdField].value+'" target="\_blank"\>'+record[\_this.fieldSettings.copyField.to].value+'\</a\>\</div\>');});}}returnMyLookUp;})();varlookUpParams={copyFieldSelectField:'参照',//参照フィールドを決めるフィールドbuttonSpace:'lookUpButton',//ボタン設置用のスペースフィールドrecordIdField:'参照ID',//参照レコードのID保存用のフィールドapp:10116,//関連付けるアプリIDcopyField:{to:'ルックアップ',//自作のルックアップフィールド},otherCopyFields:[//ほかのフィールドのコピー{to:'文字列コピー',from:'文字列'},{to:'日付コピー',from:'日付'},],viewFields:['レコード番号','数値','数値2','文字列','日付'],//コピー元のレコードの選択時に表示するフィールドquery:' 更新日時 \> "2018-07-27T09:00:00+0900" ',//絞り込みsort:' order by レコード番号 asc '//ソート};varlookUP=newMyLookUp(lookUpParams).createGetButton().createModal();kintone.events.on(['app.record.index.show'],function(event){returnlookUP.createLinks(event);});kintone.events.on(['app.record.detail.show'],function(event){returnlookUP.createLink(event);});kintone.events.on(['app.record.create.show','app.record.edit.show'],function(event){lookUP.event=event;returnlookUP.showButtons().disableOtherCopyFields(event);});})();