Migration to CRM 2011/13/15 and Converting CRM 4.0 JavaScript
I’ve seen a lot of CRM 4.0 JavaScript over the past years. A lot of
us used unsupported customization to create a better user experience that fit
the needs of our clients but sometimes these customization are unsupported… but do the job! (At one time J ). The problem comes when we need to migrate the code to a newer
version!
When using the solution to detect errors on the code we usually came
across the following:
·
.text
·
.selectSingleNode
·
ActiveXObject
·
crmForm.all
·
crmFormSubmit
So here are some examples how to convert:
CRM 4.0
|
CRM 2011/13/15
|
var id = crmFormSubmit.crmFormSubmitId.value;
|
var id = Xrm.Page.data.entity.getId();
|
var postalcode = crmForm.all.address1_postalcode.DataValue;
|
var
postalcode =
Xrm.Page.getAttribute("address1_postalcode").getValue();
|
Xrm.Page.getAttribute("new_source").getSelectedOption().text;
|
Xrm.Page.getAttribute("new_source").getText();
|
var accountValue
= accountLookup.DefaultValue[0].data = accountLookup.getValue()[0].data;
|
var
accountValue = Xrm.Page.getAttribute("sourcefield").getValue();
Xrm.Page.getAttribute("targetfield").setValue(accountValue);
|
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST",
"/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction",
'http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple');
xmlHttpRequest.setRequestHeader("Content-Type",
"text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length",
xml.length);
xmlHttpRequest.send(xml);
|
var xmlHttpRequest = new XMLHttpRequest();
xmlHttpRequest.open('POST', getServerUrl() +
'/XRMServices/2011/Organization.svc/web', false);
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/Retrieve');
xmlHttpRequest.send(xml);
|
// IE 8 and below
var
node = resultXml.selectSingleNode("//Entity/");
|
// IE 9/10, Chrome,
Firefox & Safari
parser = new DOMParser();
var node = parser.parseFromString(resultXml,
"text/xml");
node = node.getElementsByTagName("Entity/
")[0];
|
This solution is useful to convert the code automatically but be careful
some of the code is not converted properly.
Comments
Post a Comment