Hi, I'm trying to validate the mobile number with existing home phone for any leads in CRM and home phone with existing mobile for any leads in CRM.
if it is valid, I should throw an duplicate detection error with fullname of the duplicate lead. Instead of the count, I need to get the fullname value from the result set and display in the alert message
I'm new to Dynamics CRM development and java script. I need some help in this.
function CaptureMiRequirements_onSave(eventArgs) {
var mobile = Xrm.Page.getAttribute("mobilephone");
var email = Xrm.Page.getAttribute("emailaddress1");
var mainPhone = Xrm.Page.getAttribute("telephone1");
var isNull = mobile.getValue() == null && email.getValue() == null && mainPhone.getValue() == null;
var isBlank = mainPhone.getValue() == "" && mobile.getValue() == "" && email.getValue() == "";
var notificationMessage = "Error";
if (isNull || isBlank) {
Xrm.Page.ui.setFormNotification("To save this record, please enter either an Email address, Main Phone or Mobile number.", "ERROR", notificationMessage);
eventArgs.preventDefault();
eventArgs.returnValue = false;
}
else {
Xrm.Page.ui.clearFormNotification(notificationMessage);
}
if (mainPhone.getValue() != null || mobile.getValue() != null)
{
var mainphonevalue= Xrm.Page.getAttribute("telephone1").getValue();
var mobilevalue=Xrm.Page.getAttribute("mobilephone").getValue();
var context = Xrm.Page.context;
var serverUrl = context.getClientUrl();
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveResult = new XMLHttpRequest();
retrieveResult.open("GET", ODataPath +"/LeadSet?$select=FullName&$filter=(telephone1 eq mobilevalue or mobilephone eq mainphonevalue)",false);
retrieveResult.setRequestHeader("Accept", "application/json");
retrieveResult.setRequestHeader("Content-Type", "application/json; charset=utf-8?");
retrieveResult.send();
if (retrieveResult.readyState == 4 /* complete */)
{
if (retrieveResult.status == 200)
{
var retrieved = this.parent.JSON.parse(retrieveResult.responseText).d;
var Result = retrieved.results;
if (typeof Result !== "undefined")
{
var count = Result.length;
if (count>1)
{
alert("duplicate value not allowed");
executionObj.getEventArgs().preventDefault();
}
}
}
}
}
}
*This post is locked for comments