Scenario:
Validation needed when certain field exceed amount of character or length.
This is what i coded for the field validation using javascript.
Code:
// Validate Length for Field's eg. ValidateFieldLength(field, 3)
function ValidateFieldLength(attributeName, MaxLength) {
var MaxLength = Xrm.Page.data.entity.attributes.get(attributeName).getValue();
//Convertion to String
var StringMax = MaxLength.toString();
//Convertion to Int
var IntMax = parseInt(StringMax.length);
if (IntMax > MaxLength) {
alert("Exceeded the maximum length");
//Set Value Null when exceeded
Xrm.Page.data.entity.attributes.get(attributeName).setValue(null);
}
}
Validation will prompt and the field value will be clear.
// Validate Length for Field's eg. ValidateFieldLength(field, 3)
function ValidateFieldLength(attributeName, MaxLength) {
var MaxLength = Xrm.Page.data.entity.attributes.get(attributeName).getValue();
//Convertion to String
var StringMax = MaxLength.toString();
//Convertion to Int
var IntMax = parseInt(StringMax.length);
if (IntMax > MaxLength) {
alert("Exceeded the maximum length");
//Set Value Null when exceeded
Xrm.Page.data.entity.attributes.get(attributeName).setValue(null);
}
}
0 comments:
Post a Comment