Check if email address exist or not using javascript

Microsoft Dynamics CRM is a Customer Relationship Management software package developed by Microsoft
Post Reply
charm
Posts: 1
Joined: Wed Apr 25, 2012 7:09 pm

Check if email address exist or not using javascript

Post by charm »

function checkSOAP() {
// Prepare variables to retrieve the contacts.
var EmailAdd = document.getElementById("new_emailaddress").value;
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<RetrieveMultiple xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<query xmlns:q1='http://schemas.microsoft.com/crm/2006/Query'" +
" xsi:type='q1:QueryExpression'>" +
"<q1:EntityName>contact</q1:EntityName>" +
"<q1:ColumnSet xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
"<q1:Attribute>emailaddress1</q1:Attribute>" +
"<q1:Attribute>contactid</q1:Attribute>" +
"</q1:Attributes>" +
"</q1:ColumnSet>" +
"<q1:Distinct>false</q1:Distinct>" +
"<q1:Criteria>" +
"<q1:FilterOperator>And</q1:FilterOperator>" +
"<q1:Conditions>" +
"<q1:Condition>" +
"<q1:AttributeName>emailaddress1</q1:AttributeName>" +
"<q1:Operator>Like</q1:Operator>" +
"<q1:Values>" +
"<q1:Value xsi:type='xsd:string'>" + EmailAdd + "</q1:Value>" +
"</q1:Values>" +
"</q1:Condition>" +
"</q1:Conditions>" +
"</q1:Criteria>" +
"</query>" +
"</RetrieveMultiple>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/W ... veMultiple");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;

// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
// Parse and display the results.
else {
var results = resultXml.getElementsByTagName('BusinessEntity');
var msg = "";
if (results.length == 0) {
msg = "No contacts were found in " + EmailAdd + ".";
// alert(msg);
CreateContact();
return;
}
else {
msg = "Contacts found in " + searchCity + ":\r";
msg += "\Contact Id\t\t\t\tContact Full Name\r";
msg += "--------------------------------------------------------------------------------\r";
for (i = 0; i < results.length; i++) {
var idValue = results.selectSingleNode('./q1:contactid').nodeTypedValue;
var name = results.selectSingleNode('./q1:fullname').nodeTypedValue;
msg += idValue + "\t" + name + "\r";
UpdateContact(idValue);
}
// alert(msg);

}
}


}






function CreateContact() {

// Prepare values for the new contact.
var strFirstName = document.getElementById("new_name").value;
var strLastName = document.getElementById("new_lastname").value;
var strEmailAdd = document.getElementById("new_emailaddress").value;
var conferenceId = Xrm.Page.getAttribute("new_conference").getValue()[0].id;
var strSendNewsletter = Xrm.Page.getAttribute("new_sendnewsletter").getValue();
var strSendThankYouLetter = "true";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entity xsi:type='contact'>" +
//"<address1_city>" + address1_city + "</address1_city>" +
//"<address1_line1>" + address1_line1 + "</address1_line1>" +
//"<address1_postalcode>" + address1_postalcode + "</address1_postalcode>" +
//"<address1_stateorprovince>" + address1_stateorprovince + "</address1_stateorprovince>" +
//"<donotbulkemail>" + donotbulkemail + "</donotbulkemail>" +
"<emailaddress1>" + strEmailAdd + "</emailaddress1>" +
//"<telephone1>" + address1_telephone1 + "</telephone1>" +
"<firstname>" + strFirstName + "</firstname>" +
"<lastname>" + strLastName + "</lastname>" +
"<fullname>" + strFirstName + "</fullname>" +
"<new_sendnewsletter>" + strSendNewsletter + "</new_sendnewsletter>" +
"<new_sendthankyouemail>" + strSendThankYouLetter + "</new_sendthankyouemail>" +
"<new_conference>" + conferenceId + "</new_conference>" +
"</entity>" +
"</Create>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/W ... ces/Create");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;



}



function UpdateContact(idValue) {


var strFirstName = document.getElementById("new_name").value;
var strLastName = document.getElementById("new_lastname").value;
var strEmailAdd = document.getElementById("new_emailaddress").value;
var conferenceId = Xrm.Page.getAttribute("new_conference").getValue()[0].id;
var strSendNewsletter = Xrm.Page.getAttribute("new_sendnewsletter").getValue();
var strSendThankYouLetter = "true";
var authenticationHeader = GenerateAuthenticationHeader();

// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'" +
" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<Update xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<entity xsi:type='contact'>" +
"<firstname>" + strFirstName + "</firstname>" +
"<lastname>" + strLastName + "</lastname>" +
//"<address1_name>" + address1_line1 + "</address1_name>" +
//"<telephone1>" + telephone1 + "</telephone1>" +
"<fullname>" + strFirstName + "</fullname>" +
"<new_sendnewsletter>" + strSendNewsletter + "</new_sendnewsletter>" +
"<new_sendthankyouemail>" + strSendThankYouLetter + "</new_sendthankyouemail>" +
"<new_conference>" + conferenceId + "</new_conference>" +
"</entity>" +
"</Update>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/W ... ces/Update");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;

}
xaeresis
Posts: 196117
Joined: Wed Oct 04, 2023 2:39 pm

Re: Check if email address exist or not using javascript

Post by xaeresis »

сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт
xaeresis
Posts: 196117
Joined: Wed Oct 04, 2023 2:39 pm

Re: Check if email address exist or not using javascript

Post by xaeresis »

xaeresis
Posts: 196117
Joined: Wed Oct 04, 2023 2:39 pm

Re: Check if email address exist or not using javascript

Post by xaeresis »

Post Reply