Here given JavaScript to access CRM data using web service, means we can call CRM webservice using JavaScript.
Main logic for generating Account Number
a. Find the last Account number assigned to account using web service.
b. Increment last account number by one.
c. Set new generated account number to account.
=============================================
To find last account number, we are using JavaScript, and we can write this Script on "OnLoad" or "onSave" event of account.
JavaScript
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = ""+
"" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
authenticationHeader+
""+
""+
"" xsi:type='q1:QueryExpression'>"+
"account "+
""+
""+
"new_AccountNumber "+
" "+
" "+
"false "+
"" +
"" +
"new_AccountNumber " +
"Descending " +
" " +
" " +
" "+
" "+
" "+
" ";
// 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/WebServices/RetrieveMultiple");
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;
var results = resultXml.getElementsByTagName('BusinessEntity');
var i=0;
var lastAccountNumber= 0;
lastAccountNumber= results[i].selectSingleNode('./q1:new_AccountNumber).nodeTypedValue;
lastAccountNumber=eval(lastAccountNumber)+1
crmForm.all.new_AccountNumber.DataValue = lastAccountNumber;
}
Similary we can find any data of CRM entities using JavaScript and web service.
Main logic for generating Account Number
a. Find the last Account number assigned to account using web service.
b. Increment last account number by one.
c. Set new generated account number to account.
=============================================
To find last account number, we are using JavaScript, and we can write this Script on "OnLoad" or "onSave" event of account.
JavaScript
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = ""+
"
" xmlns:xsd='http://www.w3.org/2001/XMLSchema'>"+
authenticationHeader+
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
"
// 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/WebServices/RetrieveMultiple");
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;
var results = resultXml.getElementsByTagName('BusinessEntity');
var i=0;
var lastAccountNumber= 0;
lastAccountNumber= results[i].selectSingleNode('./q1:new_AccountNumber).nodeTypedValue;
lastAccountNumber=eval(lastAccountNumber)+1
crmForm.all.new_AccountNumber.DataValue = lastAccountNumber;
}
Similary we can find any data of CRM entities using JavaScript and web service.