Asked by:
need to changefor crm 2011

Question
-
i have java script snippet for crm 4.0 .... i need to make the equivalent for crm 2011. Can any one help please?
below is the snippet
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", '/mscrmservices/2007/MetadataService.asmx', false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", 'http://schemas.microsoft.com/crm/2007/WebServices/Execute');
var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
"<soap:Header>" +
"<CrmAuthenticationToken xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" +
"<AuthenticationType xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + AUTHENTICATION_TYPE + "</AuthenticationType>" +
"<OrganizationName xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>" + Xrm.Page.context.getOrgUniqueName() + "</OrganizationName>" +
"<CallerId xmlns='http://schemas.microsoft.com/crm/2007/CoreTypes'>00000000-0000-0000-0000-000000000000</CallerId>" +
"</CrmAuthenticationToken>" +
"</soap:Header>" +
"<soap:Body><Execute xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + request + "</Execute></soap:Body>" +
"</soap:Envelope>";
xmlhttp.send(soapMessage);
return xmlhttp.responseXML;
}Friday, February 20, 2015 5:12 PM
All replies
-
what changes i need to do and where ?
Friday, February 20, 2015 5:13 PM -
Hello,
You haven't provided request variable value.
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blogFriday, February 20, 2015 6:44 PMModerator -
This is not the full code . I just want to know what are changes i need to do for crm 2011 in the above snippet.Friday, February 20, 2015 7:41 PM
-
ar xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", getServerUrl, true)
// Responses will return XML. It isn't possible to return JSON.
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
xmlHttpRequest.send(soapMessage);
var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
Xrm.Page.context.getAuthenticationHeader() +
"<soap:Body><Execute xmlns=''http://schemas.microsoft.com/xrm/2011/Contracts/Services'>" + request + "</Execute></soap:Body>" +
"</soap:Envelope>";
xmlHttpRequest.send(soapMessage);
return xmlhttp.responseXML;
}function getServerUrl()
{
debugger;
var OrgServicePath = "/XRMServices/2011/Organization.svc/web";
var serverUrl = "";
if (typeof GetGlobalContext == "function") {
var context = GetGlobalContext();
serverUrl = context.getServerUrl();
}
else {
if (typeof Xrm.Page.context == "object") {
serverUrl = Xrm.Page.context.getServerUrl();
}
else {
throw new Error("Unable to access the server URL");
}
}
if (serverUrl.match(/\/$/)) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}
return serverUrl + OrgsServicePathare the above changes that i made correct for crm 2011.
Friday, February 20, 2015 7:45 PM -
It is really complicated to answer that question. I would suggest you to analyze request that you have and use SoapLogger to generate new one that is compatible with CRM 2011. Recheck that article - http://nishantrana.me/2014/08/27/updated-soaplogger-for-crm-2013-to-generate-javascript/
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blogFriday, February 20, 2015 8:20 PMModerator -
I am trying to retrieve all entities querying metadata via javascript. the request is getting passed but the response returned is null. Below is the function i used.
function gQueryMetadataService(request)
Can any one please let me know where i am going wrong ?
{
var soapMessage = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' " +
"xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
Xrm.Page.context.getAuthenticationHeader() +
"<soap:Body><Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " + request + "</Execute></soap:Body>" +
"</soap:Envelope>";
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open("POST", getServerUrl, true)
// Responses will return XML. It isn't possible to return JSON.
xmlHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
xmlHttpRequest.send(soapMessage);
return xmlHttpRequest .responseXML;
}
//*********************************************************
function gGetEntityList()
{
var request = "<Request xsi:type='RetrieveAllEntitiesRequest'>" +
"<MetadataItems>EntitiesOnly</MetadataItems>" +
"<RetrieveAsIfPublished>false</RetrieveAsIfPublished>" +
"</Request>";
var arrEntity = new Array();
var arrDisplay = new Array();
var j = 0;
var result = gQueryMetadataService(request);
var logicalNames = result.selectNodes("//CrmMetadata/LogicalName");
var displayNames = result.selectNodes("//CrmMetadata/SchemaName");
for (var i = 0; i < logicalNames.length; i++) {
//only show customizable entities
if (result.selectNodes("//CrmMetadata/IsCustomizable")[i].text == 'true') {
arrEntity[j] = logicalNames[i].text;
arrDisplay[j] = (displayNames[i]) ? displayNames[i].text : logicalNames[i].text;
j++;
}
}
return [arrEntity.sort(), arrDisplay.sort()];
}- Edited by Sashi Panigrahi Monday, February 23, 2015 3:20 PM
- Merged by Andrii ButenkoMVP, Moderator Monday, February 23, 2015 5:55 PM The same thread
Monday, February 23, 2015 3:19 PM