2

我想创建一个简单的 BMI 计算器(MS Dynamics 2011)

我有 3 个字段:

1: persons height (precision 2 - decimal formatted text box)
2. persons weight (precision 2 - decimal formatted text box)
3. BMI result - This field will display the BMI result. (also precision 2 - decimal)

我相信我需要检查两个字段 1 和 2 上的 oncreate 事件,以启动一个 javascript 函数来执行计算。但是,我对动态和 java 脚本都很陌生,需要一些帮助。

我认为这些方面的事情可能很接近。有人可以帮忙吗?

function BMICheck()
{
var Bmiresult = weight/(height/100*height/100);
Xrm.Page.getAttribute("new_bmiresulttextbox").setValue((Math.round(Bmiresult*100)/100).toString(    ));

}

我想我理解逻辑OK,语法是我的主要问题。

谢谢!

用javascript更新答案:

function BMICheck()
{

var Bmival = Xrm.Page.getAttribute("crm_heightbox_decimal")/("crm_weightbox_decimal")/100*("crm_weightbox_decimal")/100);
 Xrm.Page.getAttribute("crm_bmiresultbox").setValue((Math.round(Bmival*100)/100));

 }
4

3 回答 3

2

您的 javascript 对我来说看起来不错。.toString() 是不必要的。

关于 javascript 和 CRM 的一个有用说明是使用 F12 在 IE 中调试您的 javascript。您可以设置断点并查看到底发生了什么。

如果它产生错误,请将其包含在您的问题中。

于 2013-04-16T13:28:47.143 回答
2
  1. 了解解决方案如何工作并通过解决方案工作:http://www.dynamicscrmtrickbag.com/2011/05/28/dynamics-crm-2011-solutions-part-1/
  2. 将 JavaScript Web 资源添加到您的新解决方案
    • 打开您的解决方案或默认解决方案(通过自定义系统)
    • 单击网络资源
    • 点击新建
    • 选择脚本(JScript)
    • 单击文本编辑器并在
  3. 将 Web 资源添加到表单
    • 打开形成
    • 单击表单属性
    • 将 Web 资源添加为库
  4. 将 BMICheck 添加到关于身高和体重的 onChange 事件
    • 打开表格
    • 单击高度字段
    • 单击更改属性
    • 点击事件
    • 添加您的功能
    • 对权重字段重复
    • 注意:利用 Guido 的 null 检查来避免错误
于 2013-04-16T13:33:43.547 回答
2

javascript 没问题,除了ToStringDaryl 已经指出的。我会添加一个检查heightweight防止空值(如果字段的最小值设置大于 0.00,则可以避免检查是否为正数)

function BMICheck()
{
    var weight = Xrm.Page.getAttribute("new_weight").getValue();
    var height = Xrm.Page.getAttribute("new_height").getValue();
    if (weight != null & height != null) {
        var bmi = weight/(height/100*height/100);
        Xrm.Page.getAttribute("new_bmi").setValue(Math.round(bmi*100)/100);
    }
    else {
        alert("Need to insert Weight and Height!");
    }
}
于 2013-04-16T13:52:34.193 回答