CRM 2011:对象[object Array]没有方法'getValue'

时间:2013-11-13 04:07:32

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

我想访问当前函数中的另一个对象。我在表单上设置了一个选项,并且在更改选项集时应该检查日期值

这是我试过的 -

document.EntityScript.AssessmentStatus_OnChange = function (context) {
 if (FormScripts.FormUtilities.GetOptionSetValue("assessmentstatusoptioncode") == 803870001) {
    var AssessmentDate = Xrm.Page.getAttribute("assessmentdate");
    FormScripts.FormUtilities.ValidateDateField(AssessmentDate, false, "Assessment date cannot be future for a completed assesment.");
 }


ValidateDateField: function (Obj, allowFuture, errMsg) {
    var isValidField = true;
    if (!eval(allowFuture)) {
        var assDate = this.ReadTextFieldValue(Obj);
        if (assDate.length > 0) {
            var oToday = new Date();
            var AssessmentDate = Date.parse(assDate);
            if (AssessmentDate > oToday) {
                alert(errMsg);
                obj.setValue(null);
                Xrm.Page.getControl(Obj.getName()).setFocus();
                isValidField = false;
            }
        }
    }
    return isValidField;
}


 ReadTextFieldValue: function (fieldName) {
    var fieldValue = "";
    if (fieldName.getValue() != null) {            
        fieldValue = Xrm.Page.getAttribute(fieldName).getValue().toString();
    }

    return fieldValue;
}

但是我得到了以下错误:

Object [object Array] has no method 'getValue'

请帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

您的ReadTextFieldValue看起来不对:您传入的fieldName是属性,而不是字段名称。我想你想要这样吗

ReadTextFieldValue: function (fieldName) {
    var fieldValue = "";
    if (fieldName.getValue() != null) {            
        fieldValue = fieldName.getValue();
    }

    return fieldValue;
}

答案 1 :(得分:0)

Daryl是对的,如果你希望你的ReadTextFieldValue函数既支持字段对象,又支持字段名称作为参数,请使用:

ReadTextFieldValue: function (field) {
    var fieldValue = "";
    field = "string" == typeof field ? Xrm.Page.getAttribute(field) : field;
    if (field.getValue() != null) {
        fieldValue = field.getValue();
    }
    return fieldValue;
}