Please help me this: I have attached what I did so far
how to change a label on one of the fields.
how to Make some fields mandatory.
how to do some error checking on one of your fields.
how to Set & clear a notification on your form depending on whether there is a validation violation.
Change Spouse/Partner Name label in the Details section to Next of Kin.
Make the following fields mandatory: Job Title and Personal Notes
Do the following validation: Job title should be alphabetical, spaces - and _ only
function validatePreferredMethodOfCommunication() {
//get the value of Preffered Method of Communication code
var preferredcontactmethodcode =
Xrm.Page.getAttribute('preferredcontactmethodcode').getValue();
//if Preferred Method = Any, make all fields as non-mandatory
//else if Preferred Method = Personal Notes, make Personal Notes field mandatory
//and all other fields as non-mandatory
//else if Preferred Method = Job Title, make Job Title field mandatory
//and all other fields as non-mandatory
if(preferredcontactmethodcode == 1) {
clearAllMandatoryFields();
}
if(preferredcontactmethodcode == 2) {
clearAllMandatoryFields();
Xrm.Page.getAttribute('PersonalNotes').setRequiredLevel('required');
} else if(preferredcontactmethodcode == 3) {
clearAllMandatoryFields();
Xrm.Page.getAttribute('JobTitle').setRequiredLevel('required');
}
}
function clearAllMandatoryFields() {
//clear all mandatory fields
Xrm.Page.getAttribute('PersonalNotes').setRequiredLevel('none');
Xrm.Page.getAttribute('JobTitle').setRequiredLevel('none');
function validateName() {
var field = Xrm.Page.getAttribute('Jobtitle');
var val = field.getValue();
var passed = isAllLetters(val);
var formContext = getFormContext();
if (passed) {
if (val.length <= 30) {
formContext.getControl('Jobtitle').clearNotification();
return true;
} else {
formContext.getControl('Jobtitle').setNotification('This field must be 30 characters or less!');
return false;
}
} else {
formContext.getControl('Jobtitle').setNotification('This field must only contain alphabetical values!');
field.setValue(""); // This is to clear the field and is not needed in our case
return false;
}
}
function getFormContext() {
return typeof executionContext != 'undefined' ? executionContext.getFormContext() : Xrm.Page; // get formContext
}
function isAllLetters(inputtxt)
{
// Regex for letters, numbers, spaces, comma, question mark, exclamation mark and period => ^[\.a-zA-Z0-9,!? ]*$
if(!/^[a-zA-Z]*$/g.test(inputtxt)) // no spaces allowed, only letters.
{
// alert('This field must only contain alphabetical values');
return false;
}
else
{
return true;
}
}
function setMandatoryFields() {
Xrm.Page.getAttribute('parentcustomerid').setRequiredLevel('required');
Xrm.Page.getAttribute('Job Title').setRequiredLevel('required');
}