如果我选择不填充字段值或选项集值,则会出错

时间:2013-11-07 12:47:03

标签: javascript jquery dynamics-crm-2011 dynamics-crm

ey guys,

所以基本上我有几个选项集来自我选择一个值,并根据这些值我计算结果。 我有7个选项集,但没有必要使用所有7个选项集。因此,如果有人只选择使用3个选项集中的值并将其余部分留空,则用户会收到以下错误。

字段自定义事件出错。 事件:onSave 错误:无法获取未定义或空引用的属性“值”。

现在我意识到这个错误意味着其他选项设置值为空,但我该如何解决?

我使用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);

}

1 个答案:

答案 0 :(得分:1)

我找到了解决方案。代替 var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getSelectedOption().value;

<强> DO

var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getValue();