CRM 2011 -使用javascript设置货币字段的值

CRM 2011 - Set value of currency field with javascript

本文关键字:货币 字段 设置 javascript 2011 使用 CRM      更新时间:2023-09-26

我真的无法找到如何从货币字段检索值并将其设置为另一个实体的另一个货币字段的值。

我下面的代码不工作:

var entities = retrieveRecords("trainingSet?$filter=trainingId eq guid'" + GetLookUpData("trainingid").id + "'");
    if (entities != null) {
        if (entities.d.results.length > 0) {
            if (entities.d.results[0]["Price"] != null) {
                alert(entities.d.results[0]["Price"]);
                Xrm.Page.getAttribute("price").setValue(entities.d.results[0]["Price"].getValue());
                Xrm.Page.getAttribute("price").setSubmitMode("always");
            }
        }
    }

错误提示控件只除数字或null。

任何帮助都将非常感激!谢谢!

我以前使用过这个,尽管我不是eval的粉丝。

function SetMoneyAttribute(value, attribute) {
                      Xrm.Page.getAttribute(attribute)
                    .setValue(parseFloat(eval(value)));
        }

这是一篇关于使用查询值设置表单字段的博文。

http://crmscape.blogspot.com/2011/03/crm - 2011 odata - json -和- crm forms.html

//mimic crm object model
var Xrm = { 
    Page : { 
        getAttribute : function(sAttr) { 
            return { 
                setValue : function(nValue) { 
                    alert(sAttr + ': ' + nValue);
                }
            }; 
        }  
    } 
};
function mySetValue(sAttr, nValue, nDefault) {
    Xrm.Page.getAttribute(sAttr)
        .setValue(
        !isNaN(nValue = parseFloat(nValue)) || 
        !isNaN(nValue = nDefault)
        ? nValue
        : null);                
} 
//call with various types of values
mySetValue("new_attr1",0);
mySetValue("new_attr2","");
mySetValue("new_attr3",4);
mySetValue("new_attr4",34.3434);
mySetValue("new_attr5","545.43");
mySetValue("new_attr6",{},0);
//mySetValue("new_attr7",entities.d.results[0]["Price"], 100.00);

如错误所述,属性只需要数字或null。为了遵守第一个isNaN检查是否parseFloat返回一个数字。如果返回undefined,则尝试从默认值(如果提供)中获取数字。如果这是未定义的,而不是一个数字,那么它分配一个空值。如果你不需要默认值,或者默认值总是已知的(即null或0.0),你可以省略第二个isNaN测试