0

i want to access another object in my current function. i have a option set on my form and on change of option set it should check the date value

This is what i have tried -

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;
}

But with i am getting the follwing error :

Object [object Array] has no method 'getValue'

please help me resolve this.

1
  • Which line is throwing the error? Commented Nov 13, 2013 at 10:33

2 Answers 2

1

Your ReadTextFieldValue looks wrong: Your fieldName being passed in is an attribute, not a field name. I think you want it like this

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

    return fieldValue;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Daryl is right, and if you want your ReadTextFieldValue function to support both a field object or just the name of a field as parameter, use this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.