レコード一覧「すべて」のカラムは、フィールドを作成した順に並びます。
例えば、下のようなフォームがあったとしても、
作成順がバラバラだと、一覧のカラムの順番もバラバラになります。
今回は、1クリックでフォームレイアウト順の一覧を生成するカスタマイズを紹介します。
コード
下記「sample.js」を読み込みます。 アプリJS、全体JSのどちらで読み込んでも動作します。
・sample.js
(function(){"use strict";kintone.events.on(['app.record.index.show',],function(event){varshowRecordId=true;varcreateViewButton=document.createElement('button');createViewButton.innerText='フォームレイアウト順の一覧を作成';createViewButton.addEventListener('click',function(){kintone.Promise.all([kintone.api(kintone.api.url('/k/v1/app/form/layout',true),'GET',{app:kintone.app.getId()}),kintone.api(kintone.api.url('/k/v1/app/views',true),'GET',{app:kintone.app.getId()}),]).then(function(responses){varlayout=responses[0].layout;varviews=responses[1].views;varfields=[].concat.apply([],layout.map(function(row){if(row.type==='SUBTABLE')returnrow.code;if(row.type==='GROUP')return[].concat.apply([],row.layout.map(function(rowInGroup){returnrowInGroup.fields.filter(function(field){return(field.type!=='LABEL'&&field.type!=='REFERENCE\_TABLE'&&field.type!=='SPACER'&&field.type!=='HR');}).map(function(field){returnfield.code;});}));returnrow.fields.filter(function(field){return(field.type!=='LABEL'&&field.type!=='REFERENCE\_TABLE'&&field.type!=='SPACER'&&field.type!=='HR');}).map(function(field){returnfield.code;});}));if(showRecordId&&fields.indexOf('レコード番号')===-1)fields.unshift('レコード番号');if(!views.フォームレイアウト順)Object.keys(views).forEach(function(viewName){views[viewName].index++;});views.フォームレイアウト順={index:0,type:'LIST',name:'フォームレイアウト順',fields:fields};returnkintone.api(kintone.api.url('/k/v1/preview/app/views',true),'PUT',{app:kintone.app.getId(),views:views});}).then(function(){returnkintone.api(kintone.api.url('/k/v1/preview/app/deploy',true),'POST',{apps:[{app:kintone.app.getId()}]});}).then(function(){returnnewkintone.Promise(function(resolve){setInterval(function(){kintone.api(kintone.api.url('/k/v1/preview/app/deploy',true),'GET',{apps:[kintone.app.getId()]}).then(function(response){if(response.apps[0].status==='SUCCESS')resolve();});},1000);});}).then(function(){alert('フォームレイアウト順の一覧を作成しました。');location.reload();});});kintone.app.getHeaderMenuSpaceElement().appendChild(createViewButton);});})();