2016-09-11 8 views
0

Ich bin neu bei Microsoft Dynamics CRM und ich arbeite mit CRM 2015. Ich arbeite mit CRM 2015 und ich wurde beauftragt, ein Fehlerskript zu beheben für CRM 2011. Es sieht aus wie eine alte Syntax und ich weiß nicht, wie man es an JS für CRM 2015 anpassen. Das Skript verwalten den Benutzer Rollen und Rollennamen und ich habe die Daten über fetchXML abrufen.wie man altes JS CRM 2011 an CRM 2015 anpasst

function onChangeValutator() 
 
{ 
 
    var idUser = Xrm.Page.getAttribute("erm_valutatorid").getValue()[0].id; 
 

 
    // Use the Xrm.Page.context.getAuthenticationHeader() method 
 
    // available from the CRM form to generate the Soap header text. 
 
    var authenticationHeader = Xrm.Page.context.getAuthenticationHeader(); 
 

 
    // Define the SOAP XML to access Microsoft Dynamics CRM Web service. 
 
    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>" + 
 
    // Specify the RetrieveMultiple message. 
 
    "<RetrieveMultiple xmlns="+ 
 
    "\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
 
    // Specify that this is a QueryByAttribute query. 
 
    "<query xmlns:q1="+ 
 
    "\"http://schemas.microsoft.com/crm/2006/Query\" "+ 
 
    "xsi:type=\"q1:QueryByAttribute\">" + 
 
    // Query the customeraddress entity. 
 
    "<q1:EntityName>erm_source</q1:EntityName>" + 
 
    // Set the columns you want to return. 
 
    "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
 
    "<q1:Attributes>" + 
 
    "<q1:Attribute>erm_roleid</q1:Attribute>" + 
 
    "</q1:Attributes>" + 
 
    "</q1:ColumnSet>" + 
 
    // Specify the attribute that you are querying on. 
 
    "<q1:Attributes>" + 
 
    "<q1:Attribute>erm_sourceid</q1:Attribute>" + 
 
    "</q1:Attributes>" + 
 
    // Set the value of the attribute using the customerid 
 
    // value of the case record. 
 
    "<q1:Values>" + 
 
    "<q1:Value xsi:type=\"xsd:string\">"+ 
 
    idUser+ 
 
    "</q1:Value>" + 
 
    "</q1:Values>" + 
 
    "</query>" + 
 
    "</RetrieveMultiple>" + 
 
    "</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/RetrieveMultiple"); 
 
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); 
 
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length); 
 
    xmlHttpRequest.send(xml); 
 
    var doc = xmlHttpRequest.responseXML; 
 
    var source = doc.selectSingleNode("//BusinessEntity"); 
 

 
    var guidSource = source.childNodes[0]; 
 

 
    if (guidSource.text != null) 
 
    { 
 
     // Define the SOAP XML to access Microsoft Dynamics CRM Web service. 
 
     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>" + 
 
     // Specify the RetrieveMultiple message. 
 
     "<RetrieveMultiple xmlns="+ 
 
     "\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
 
     // Specify that this is a QueryByAttribute query. 
 
     "<query xmlns:q1="+ 
 
     "\"http://schemas.microsoft.com/crm/2006/Query\" "+ 
 
     "xsi:type=\"q1:QueryByAttribute\">" + 
 
     // Query the customeraddress entity. 
 
     "<q1:EntityName>erm_companyrole</q1:EntityName>" + 
 
     // Set the columns you want to return. 
 
     "<q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
 
     "<q1:Attributes>" + 
 
     "<q1:Attribute>erm_name</q1:Attribute>" + 
 
     "</q1:Attributes>" + 
 
     "</q1:ColumnSet>" + 
 
     // Specify the attribute that you are querying on. 
 
     "<q1:Attributes>" + 
 
     "<q1:Attribute>erm_companyroleid</q1:Attribute>" + 
 
     "</q1:Attributes>" + 
 
     // Set the value of the attribute using the customerid 
 
     // value of the case record. 
 
     "<q1:Values>" + 
 
     "<q1:Value xsi:type=\"xsd:string\">"+ 
 
     guidSource.text+ 
 
     "</q1:Value>" + 
 
     "</q1:Values>" + 
 
     "</query>" + 
 
     "</RetrieveMultiple>" + 
 
     "</soap:Body>" + 
 
     "</soap:Envelope>"; 
 
      
 
     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); 
 
     doc = xmlHttpRequest.responseXML; 
 
     var role = doc.selectSingleNode("//BusinessEntity"); 
 
     var roleName = role.childNodes[0]; 
 
     
 
     var lookupItem = new Array(); 
 
     lookupItem[0] = new Object(); 
 
     
 
     lookupItem[0].name = roleName.text; 
 
     lookupItem[0].entityType = "erm_companyrole"; 
 
     lookupItem[0].id = guidRSource.text; 
 
     
 
     Xrm.Page.getAttribute("erm_valutatorroleid").setValue(lookupItem); 
 
     
 
    } \t \t  
 
}

+0

Nur eine Meinung, aber wenn Sie für CRM 2016 und darüber hinaus vorbereitet sein möchten, sollten Sie SOAP-Endpunktanforderungen abbrechen und zum ODATA-Endpunkt wechseln. – Filburt

+0

@Filburt Ich werde auf ODATA wechseln, aber ich habe noch nicht mit ODATA gearbeitet. Ich wollte ein Standardformat, um Benutzerrollen in CRM 2016 mit fetchXML zu verwalten. Das ist alles was ich denken könnte. – zhaila

Antwort

1

Ihre Anfragen werden mit dem Dynamics CRM 4.0 Web-Service-Endpunkt, der veraltet. Entfernen Sie den Authentifizierungsheader von der SOAP-Nachricht und ersetzen Sie die Endpunktadresse "/mscrmservices/2007/CrmService.asmx" durch "xrmservices/2011/organization.svc/web". Ein schönes Beispiel finden Sie here.

Mit der Einführung der Web-API in Dynamics CRM 2016 hat Microsoft den SOAP-Endpunkt insgesamt abgelehnt, aber versprochen, ihn auch in den kommenden Jahren zu unterstützen.

+0

Ich habe das. Aber ich möchte Formular CRM 4.0 zu CRM 2015 aktualisieren. xrmservices/2011/Organisation.svc/Web ist für CRM 2011 und ich möchte es in ODATA konvertieren, aber ich weiß nicht, hoe es anpassen. – zhaila

+0

xrmservices/2011/organization.svc' wurde mit CRM 2011 eingeführt und war bisher der einzige SOAP-Endpunkt für CRM. –

+0

ja, aber ich muss es mit fetchXML konvertieren. – zhaila

Verwandte Themen