以下のように変更しても、
Uncaught (in promise) TypeError: Cannot set property ‘innerHTML’ of null
というエラーとなります。toLocaleString()をしているからなのか、TotalQuantityフィールドは、スペースフィールドの場合には問題ありません。(教えていただいたので)
TotalQuantityフィールドを計算フィールドとして活用したい意向があります。
--------以下---------
//kintone.app.record.getSpaceElement(“TotalQuantity”).innerHTML =
kintone.app.record.getFieldElement(“TotalQuantity”).innerHTML =
records.reduce(function(sum, record){
return sum + Number(record.残量.value);
}, 0).toLocaleString();
りょうすけ様
お世話になっております。 cstapの江田です。
kintone.app.record.getSpaceElement()は、レコード詳細表示画面でしか利用できません。
https://developer.cybozu.io/hc/ja/articles/201942014#step3
フォーム画面でフィールド要素を取得する場合は、DOMのclass名などから判別する必要があります。
(function(){"use strict";vargetFieldElementOnInputPage=function(fieldName){varresult;[].forEach.call(document.getElementsByClassName('control-gaia'),function(fieldElement){if(fieldElement.getElementsByClassName('control-label-text-gaia')[0].innerHTML==fieldName){result=fieldElement.getElementsByTagName('input')[0];}});returnresult;}kintone.events.on(['app.record.create.show','app.record.edit.show'],function(event){...// フィールドコードではなくフィールド名で指定getFieldElementOnInputPage('TotalQuantity').value=records.reduce(function(sum,record){returnsum+Number(record.残量.value);},0).toLocaleString();...});})();
※kintoneの仕様変更により動作しなくなる可能性があります。
ご教授ありがとうございます。
DOMのclass名で試行してみようかなと思います。ができるかなぁ~
すみません。コードご提示いただいておりました(^_^;
むずかしいですね(´・_・`)