This code / function can be used to retrieve a particular field/attribte from related records. It passes back an XML doc which can then be parsed to get the particular value.
I have substituted the <> chars with [ and ] due to the probs of rendering in blogger
//--------------------------------------------------------------------------------------------------
getattribByLookup = function(entityForList, attribForFilter, idToFetch, attribToReturn ) {
//--------------------------------------------------------------------------------------------------
var f = crmForm.all;
var xml = "" +
"[?xml version=\"1.0\" encoding=\"utf-8\"?]" +
"[?xml:namespace prefix = soap /][soap:envelope xsd="\" xsi="\" soap="\"]" +
" [soap:body]" +
" [query xmlns="\" type="\" q1="\"]" +
" [?xml:namespace prefix = q1 /][q1:entityname]" + entityForList + "[/q1:entityname]" +
" [q1:columnset type="\"]" +
" [q1:attributes]" +
" [q1:attribute]" + attribToReturn + "[/q1:attribute]" +
" [/q1:attributes]" +
" [/q1:columnset]" +
" [q1:distinct]true[/q1:distinct]" +
" [q1:criteria]" +
" [q1:filteroperator]And[/q1:filteroperator]" +
" [q1:conditions]" +
" [q1:condition]" +
" [q1:attributename]" + attribForFilter + "[/q1:attributename]" +
" [q1:operator]Equal[/q1:operator]" +
" [q1:values]" +
" [q1:value type="\"]" + idToFetch + "[/q1:value]" +
" [/q1:values]" +
" [/q1:condition]" +
" [/q1:conditions]" +
" [/q1:criteria]" +
" [/query]" +
" [/soap:body]" +
"[/soap:envelope]" +
"";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
return( resultXml );
};
No comments:
Post a Comment