4. Dezember 2012 12:03
function GetAttributeValueFromID(sEntityName, sGUID, sAttributeName)
{
var sXml = "";
var oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
// set up the SOAP message
sXml += "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
sXml += "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"";
sXml += " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"";
sXml += " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";
sXml += GenerateAuthenticationHeader()
sXml += " <soap:Body>";
sXml += " <entityName xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sEntityName + "</entityName>";
sXml += " <id xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sGUID + "</id>";
sXml += " <columnSet xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\"";
sXml += " xmlns:q=\"http://schemas.microsoft.com/crm/2006/Query\"";
sXml += " xsi:type=\"q:ColumnSet\"><q:Attributes><q:Attribute>" + sAttributeName + "</q:Attribute></q:Attributes></columnSet>";
sXml += " </soap:Body>";
sXml += " </soap:Envelope>";
// send the message to the CRM Web service
oXmlHttp.Open("POST", "/MsCrmServices/2006/CrmService.asmx", false);
oXmlHttp.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");
oXmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
oXmlHttp.setRequestHeader("Content-Length", sXml.length);
oXmlHttp.send(sXml);
// retrieve response and find attribute value
var result = oXmlHttp.responseXML.selectSingleNode("//q1:" + sAttributeName);
if (result == null)
return "";
else
return result.text;
}
4. Dezember 2012 17:05
5. Dezember 2012 09:28
13. Dezember 2012 09:38
function GetAttributeValueWithOData(sSelectstatement){
var serverUrl = "http://" + window.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
// Creating the Odata Endpoint
var oDataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var retrieveReq = new XMLHttpRequest();
var Odata = oDataPath + sSelectstatement;
retrieveReq.open("GET", Odata, false);
retrieveReq.setRequestHeader("Accept", "application/json");
retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveReq.send();
if (retrieveReq.readyState == 4 /* complete */) {
var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;
return retrieved.results[0];
}
}
/*Möglicher Beispielaufruf, bei dem man danach auf ein bestimmtes Feld hier EMailAdress1 zugreifen kann*/
var Kunde = new Array();
Kunde = Xrm.Page.getAttribute("customerid").getValue();
var kundeid = Kunde[0].id;
alert(GetAttributeValueWithOData("/ContactSet?$select=EMailAddress1&$filter=ContactId eq guid'" + kundeid + "'").EMailAddress1);
/*Möglicher Beispielaufruf, bei dem man danach auf alle Felder des Kontakts zugreifen kann*/
var Kunde = new Array();
Kunde = Xrm.Page.getAttribute("customerid").getValue();
var kundeid = Kunde[0].id;
var resultKunden = GetAttributeValueWithOData("/ContactSet?$select=*&$filter=ContactId eq guid'" + kundeid + "'");
alert(resultKunden.EMailAddress1);
alert(resultKunden.FirstName);
/*Möglicher Beispielaufruf, bei dem man danach auf die Felder zugreien kann, die im Select angegeben sind.
Funktioniert aber bei uns im Moment nicht, obwohl das im SDK so als Aufruf angegeben*/
var Kunde = new Array();
Kunde = Xrm.Page.getAttribute("customerid").getValue();
var kundeid = Kunde[0].id;
var resultKunden = GetAttributeValueWithOData("/ContactSet?$select=EMailAdress1,FirstName&$filter=ContactId eq guid'" + kundeid + "'");
alert(resultKunden.EMailAddress1);
alert(resultKunden.FirstName);