<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MSCRM Blogger &#187; lookup</title>
	<atom:link href="http://mscrmblogger.com/tag/lookup/feed/" rel="self" type="application/rss+xml" />
	<link>http://mscrmblogger.com</link>
	<description>Achieving it all with Microsoft Dynamics CRM™</description>
	<lastBuildDate>Wed, 30 Nov 2011 00:34:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Lookup a lookup on another entity using JScript</title>
		<link>http://mscrmblogger.com/2009/10/15/lookup-a-lookup-on-another-entity-using-jscript/</link>
		<comments>http://mscrmblogger.com/2009/10/15/lookup-a-lookup-on-another-entity-using-jscript/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 20:37:32 +0000</pubDate>
		<dc:creator>Carlton Colter</dc:creator>
				<category><![CDATA[Extensions]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Web Resources]]></category>
		<category><![CDATA[crm]]></category>
		<category><![CDATA[crm 4]]></category>
		<category><![CDATA[crm4]]></category>
		<category><![CDATA[jscript]]></category>
		<category><![CDATA[lookup]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[microsoft dynamics CRM 4]]></category>

		<guid isPermaLink="false">http://mscrmblogger.com/?p=188</guid>
		<description><![CDATA[Do you need the value of a lookup?  I have written this bit of code to look a lookup value stored on another entity.  Like finding the Customer lookup on an Incident (Case).  Here is a bit of code that can lookup a lookup on any entity in CRM.]]></description>
			<content:encoded><![CDATA[<p>Do you need the value of a lookup?  I have written this bit of code to look a lookup value stored on another entity.  Like finding the Customer lookup on an Incident (Case).</p>
<ul>
<li>ID: The unique id value of the entity&#8217;s object</li>
<li>ENTITY: The name of the entity to lookup</li>
<li>IDFIELD: The entity&#8217;s primary id field name, like accountid, incidentid, etc.</li>
<li>LOOKUPFIELD: The name of the field you want to lookup, like customerid</li>
<li>RETURNTYPE: The name of the entity&#8217;s return type, like contact or account.  If there are multiple possible, then specify &#8220;multiple&#8221; and it will pass back the type instead of type name.  If you specify &#8220;value&#8221; it will return just the value.</li>
</ul>
<hr />
<pre name="code" class="javascript">
function getEntityLookup(id, entity, idfield, lookupfield, returntype) {
    var xml = &quot;&quot; +
	&quot;&lt; ?xml version='1.0' encoding='utf-8'?&gt;&quot; +
	&quot;&lt;soap :Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&quot; +
	&quot; xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'&quot; +
	&quot; xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;&quot; +
	GenerateAuthenticationHeader() +
	&quot;&lt;/soap&gt;&lt;soap :Body&gt;&quot; +
	&quot;&lt;fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'&gt;&quot; +
	&quot;&lt;fetchxml&gt;&quot; +
	&quot; &amp;lt;fetch mapping='logical' count='1'&amp;gt;&quot; +
	&quot; &amp;lt;entity name='&quot; + entity + &quot;'&amp;gt;&quot; +
	&quot; &amp;lt;attribute name='&quot; + lookupfield + &quot;' /&amp;gt;&quot; +
	&quot; &amp;lt;filter&amp;gt;&quot; +
	&quot; &amp;lt;condition attribute='&quot; + idfield + &quot;' operator='eq' value='&quot; + id + &quot;' /&amp;gt;&quot; +
	&quot; &amp;lt;/filter&amp;gt;&quot; +
	&quot; &amp;lt;/entity&amp;gt;&quot; +
	&quot; &amp;lt;/fetch&amp;gt;&quot; +
	&quot;&lt;/fetchxml&gt;&quot; +
	&quot;&lt;/fetch&gt;&quot; +
	&quot;&lt;/soap&gt;&quot; +
	&quot;&quot;;

    var xmlHttpRequest = new ActiveXObject(&quot;Msxml2.XMLHTTP&quot;);
    xmlHttpRequest.Open(&quot;POST&quot;, &quot;/mscrmservices/2007/CrmService.asmx&quot;, false);
    xmlHttpRequest.setRequestHeader(&quot;SOAPAction&quot;, &quot;http://schemas.microsoft.com/crm/2007/WebServices/Fetch&quot;);
    xmlHttpRequest.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml; charset=utf-8&quot;);
    xmlHttpRequest.setRequestHeader(&quot;Content-Length&quot;, xml.length);
    xmlHttpRequest.send(xml);

    var resultXml = xmlHttpRequest.responseXML;
    var resultSet = resultXml.text;
    resultSet.replace('&amp;lt;', '&lt; ');
    resultSet.replace('&amp;gt;', '&gt;');

    var oXmlDoc = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;);
    oXmlDoc.async = false;
    oXmlDoc.loadXML(resultSet);

    var result = oXmlDoc.getElementsByTagName(lookupfield);
    if (returntype == 'value') return result[0].text;

    var lookupItem = new Object();
    for (var i = 0; i &lt; result[0].attributes.length; i++) {
        var att = result[0].attributes[i];
        if (returntype == 'multiple' &amp;&amp; att.name == &quot;type&quot;) lookupItem.type = att.value;
        if (att.name == &quot;name&quot;) lookupItem.name = att.value;
    }
    if (returntype != 'multiple') lookupItem.typename = returntype;

    lookupItem.id = result[0].text;

    return lookupItem;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://mscrmblogger.com/2009/10/15/lookup-a-lookup-on-another-entity-using-jscript/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

