We are upgrading CRM 2011 to CRM 2013. The Custom Code Validation tool flagged the method: GenerateAuthenticationHeader()
.
The question is what would I replace this method to be so that it works in CRM 2013. As it is giving me "undefined" when I run it.
I have looked up many sources. One site says uses SDK REST, but it does not give the appropriate information.
If you can kindly let me know how I can replace the method GenerateAuthenticationHeader()
it would be much appreciated.
The code is given below:
function GetAttributeValueFromID(sEntityName, sGUID, sAttributeName, isTextField)
{
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\">" + GenerateAuthenticationHeader() +
" <soap:Body>" +
" <Execute xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <Request xsi:type=\"RetrieveRequest\" ReturnDynamicEntities=\"false\">" +
" <Target xsi:type=\"TargetRetrieveDynamic\">" +
" <EntityName>" + sEntityName + "</EntityName>" +
" <EntityId>" + sGUID + "</EntityId>" +
" </Target>" +
" <ColumnSet xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>" + sAttributeName + "</q1:Attribute>" +
" </q1:Attributes>" +
" </ColumnSet>" +
" </Request>" +
" </Execute>" +
" </soap:Body>" +
"</soap:Envelope>" + "";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Execute");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var result = null;
if (isTextField)
{
result = xmlHttpRequest.responseXML.selectSingleNode("//q1:" + sAttributeName).text;
}
else
{
result = xmlHttpRequest.responseXML.selectSingleNode("//q1:" + sAttributeName).getAttribute('name');
}
if (result == null)
{
return '';
}
else
return result;
}