皆さん、
したがって、基本的に、値を選択するオプションセットがいくつかあり、それらの値に基づいて結果を計算します。7 つのオプション セットがありますが、7 つすべてを使用する必要はありません。SO 誰かが 3 つのオプション セットの値のみを使用することを選択し、残りを空のままにすると、ユーザーは次のエラーを受け取ります。
フィールドカスタマイズイベントでエラーが発生しました。イベント: onSave エラー: 未定義または null 参照のプロパティ '値' を取得できません。
このエラーは、他のオプション セットの値が空であることを意味していることに気付きましたが、どうすればこれを回避できますか?
オプションセットの値を使用してテキストフィールドの値を乗算し、結果を取得するためにjavascriptを使用しています。これが私のコードです
function cashTotal()
{
if (Xrm.Page.ui.getFormType() == 1)
{
var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getSelectedOption().value;
var bill1Text = Xrm.Page.getAttribute("inmate_cashbill1_text").getValue();
var result1 = bill1 * bill1Text;
Xrm.Page.getAttribute("inmate_total1").setValue(result1);
var bill2 = Xrm.Page.getAttribute("inmate_cashbills2").getSelectedOption().value;
var bill2Text = Xrm.Page.getAttribute("inmate_cashbill2_text").getValue();
var result2 = bill2 * bill2Text;
Xrm.Page.getAttribute("inmate_total2").setValue(result2);
var bill5 = Xrm.Page.getAttribute("inmate_cashbillls5").getSelectedOption().value;
var bill5Text = Xrm.Page.getAttribute("inmate_cashbill5_text").getValue();
var result5 = bill5 * bill5Text;
Xrm.Page.getAttribute("inmate_total5").setValue(result5);
var bill10 = Xrm.Page.getAttribute("inmate_cashbills10").getSelectedOption().value;
var bill10Text = Xrm.Page.getAttribute("inmate_cashbill10_text").getValue();
var result10 = bill10 * bill10Text;
Xrm.Page.getAttribute("inmate_total10").setValue(result10);
var bill20 = Xrm.Page.getAttribute("inmate_cashbills20").getSelectedOption().value;
var bill20Text = Xrm.Page.getAttribute("inmate_cashbill20_text").getValue();
var result20 = bill20 * bill20Text;
Xrm.Page.getAttribute("inmate_total20").setValue(result20);
var tmp = result1 + result2 + result5 + result10 + result20;
Xrm.Page.getAttribute("inmate_cashtotal").setValue(tmp);
}