Asked by:
AutoComplete functionality without using GenerateAuthenticationHeader() in CRM 2013

Question
-
Hi All,
I have implemented auto complete functionality for account name in CRM 2011 online version. I have used the GenerateAuthenticationHeader() function and am passing the admin Guid in that. This will override the current user GUId and the auto complete functionality will show the account name created by all users.
In CRM 2013 version GenerateAuthenticationHeader() is not supported and XRM.Page.Context.getAuthenticationHeader is also deprecated.
Please find the following code i have written to read the account name where i 'm using GenerateAuthenticationHeader.
AutoCompleteFeatureForAccountName: function (fieldName) { //debugger; // Prepare variables to retrieve the company names. //var companyName = Xrm.Page.getAttribute("companyname").getValue(); // var companyNameControl = Xrm.Page.ui.controls.get("companyname"); // var companyName = companyNameControl.getValue(); var companyNameControl = document.getElementById(fieldName); var companyName = companyNameControl.value; var control = Xrm.Page.getAttribute(fieldName); var results; if (companyName != "") { var filtercompanyName = companyName + '%'; } var authenticationHeader = GenerateAuthenticationHeader(); var value = "%*%"; // 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/xrm/2011/Contracts/Services' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>" + "<query xmlns:q1='http://schemas.microsoft.com/xrm/2011/Contracts'" + " xsi:type='q1:QueryExpression'>" + "<q1:EntityName>account</q1:EntityName>" + "<q1:ColumnSet xsi:type='q1:ColumnSet'>" + "<q1:Attributes>" + "<q1:Attribute>name</q1:Attribute>" + "<q1:Attribute>ownerid</q1:Attribute>" + "</q1:Attributes>" + "</q1:ColumnSet>" + "<q1:Distinct>false</q1:Distinct>" + "<q1:Criteria>" + "<q1:FilterOperator>And</q1:FilterOperator>" + "<q1:Conditions>" + "<q1:Condition>" + "<q1:AttributeName>name</q1:AttributeName>" + "<q1:Operator>Like</q1:Operator>" + "<q1:Values>" + "<q1:Value xsi:type='xsd:string'>" + filtercompanyName + "</q1:Value>" + "</q1:Values>" + "</q1:Condition>" + "</q1:Conditions>" + "</q1:Criteria>" + "<q1:Count>10</q1:Count>" + "</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/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; // 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 { results = resultXml.getElementsByTagName('BusinessEntity'); return results; } } };
function GenerateAuthenticationHeader() { var xml = new StringBuilder; xml.Append('<soap:Header><CrmAuthenticationToken xmlns="'); xml.Append(CrmEncodeDecode.CrmXmlEncode(CRM2007_WEBSERVICE_NS)); xml.Append('"><AuthenticationType xmlns="'); xml.Append(CrmEncodeDecode.CrmXmlEncode(CRM2007_CORETYPES_NS)); xml.Append('">'); xml.Append(CrmEncodeDecode.CrmXmlEncode(AUTHENTICATION_TYPE)); xml.Append('</AuthenticationType><CrmTicket xmlns="'); xml.Append(CrmEncodeDecode.CrmXmlEncode(CRM2007_CORETYPES_NS)); xml.Append('"></CrmTicket><OrganizationName xmlns="'); xml.Append(CrmEncodeDecode.CrmXmlEncode(CRM2007_CORETYPES_NS)); xml.Append('">'); xml.Append(CrmEncodeDecode.CrmXmlEncode(ORG_UNIQUE_NAME)); xml.Append('</OrganizationName><CallerId xmlns="'); xml.Append(CrmEncodeDecode.CrmXmlEncode(CRM2007_CORETYPES_NS)); xml.Append('">3A78654A-F81B-4622-9613-55D2329B4AF4</CallerId></CrmAuthenticationToken></soap:Header>'); return xml.ToString(); }
Please help me in achieving the same functionality in CRM 2013 online version.
Thanks,
Saishri. N
Tuesday, December 17, 2013 2:01 PM
All replies
-
Hi All,
Please help me in finding a solution for the above issue.
Thanks,
Saishri, N
Wednesday, December 18, 2013 6:25 AM -
Hello,
To make your code work you will have to rewrite it using CRM 2013 endpoints. You can use OrganizationData or Organization endpoints.
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blog- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, December 19, 2013 12:37 PM
Wednesday, December 18, 2013 9:55 AMModerator