<?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>entwicklungsgedanken &#187; lookup</title>
	<atom:link href="http://www.entwicklungsgedanken.de/tag/lookup/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entwicklungsgedanken.de</link>
	<description>Verschiedene Gedanken rund um die Softwareentwicklung</description>
	<lastBuildDate>Thu, 29 Jul 2010 11:09:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Updating existing lookup fields in SharePoint</title>
		<link>http://www.entwicklungsgedanken.de/2010/02/01/updating-existing-lookup-fields-in-sharepoint/</link>
		<comments>http://www.entwicklungsgedanken.de/2010/02/01/updating-existing-lookup-fields-in-sharepoint/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 11:39:50 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[lookup]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[SchemaXml]]></category>
		<category><![CDATA[update]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/2010/02/01/updating-existing-lookup-fields-in-sharepoint/</guid>
		<description><![CDATA[Creating lookup-fields only via XML-Definition is not possible. You need the ID of the Web hosting the list and the ID of the list hosting the data the lookup field is connected to. This information can only be retrieved when both entities are created… Object model?! When looking into the SPFieldLookup-class you find the properties [...]]]></description>
			<content:encoded><![CDATA[<p>Creating lookup-fields only via XML-Definition is not possible. You need the ID of the Web hosting the list and the ID of the list hosting the data the lookup field is connected to. This information can only be retrieved when both entities are created…</p>
<h3>Object model?!</h3>
<p>When looking into the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.aspx">SPFieldLookup</a>-class you find the properties LookupField, LookupList and LookupWebId. LookupWebId and LookupField can easily be set via the object model. The documentation says that <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldlookup.lookuplist.aspx">LookupList is read and writeable</a> which is not true. Setting LookupList throws an exception stating out “Cannot change the lookup list of the lookup field.”.</p>
<h3>SchemaXml and Regex to the rescue</h3>
<p>The <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfield.schemaxml.aspx">SchemaXml-property</a> of a SPField can be used to manipulate the LookupList. One stumbling block is that you do not know the Guid of the LookupList currently stored in the schema. Even if you define a Guid inside your xml-field-definition SharePoint puts in an other Guid. Here a simple regular expression comes to help.</p>
<p><strong>The code for connecting a site-column with a list somewhere in some web:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Declarations (myWeb is the context given by a feature receiver scoped &quot;web&quot;)</span>
var rx <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;List=<span style="color: #008080; font-weight: bold;">\&quot;</span>([^<span style="color: #008080; font-weight: bold;">\&quot;</span>]*)<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, RegexOptions.<span style="color: #0000FF;">IgnoreCase</span> <span style="color: #008000;">|</span> RegexOptions.<span style="color: #0000FF;">ECMAScript</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
var root <span style="color: #008000;">=</span> myWeb.<span style="color: #0000FF;">Site</span>.<span style="color: #0000FF;">RootWeb</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// myListInstance is an instance of a SPList existing somewhere</span>
var lookupField <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPFieldLookup<span style="color: #000000;">&#41;</span>root.<span style="color: #0000FF;">Fields</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;MyLookupField&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
var xml <span style="color: #008000;">=</span> lookupField.<span style="color: #0000FF;">SchemaXml</span><span style="color: #008000;">;</span>
xml <span style="color: #008000;">=</span> rx.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>xml, <span style="color: #FF0000;">String</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;List=<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, myListInstance.<span style="color: #0000FF;">ID</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;B&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
lookupField.<span style="color: #0000FF;">SchemaXml</span> <span style="color: #008000;">=</span> xml<span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Do not call update here!</span>
<span style="color: #008080; font-style: italic;">// Quote from MSDN &quot;Do not call the Update method when using the SchemaXml  property to modify a field.&quot;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Fetch the field again and apply the web-id</span>
var lookupFieldReFetch <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>SPFieldLookup<span style="color: #000000;">&#41;</span>root.<span style="color: #0000FF;">Fields</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;MyLookupField&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
lookupFieldReFetch.<span style="color: #0000FF;">LookupWebId</span> <span style="color: #008000;">=</span> myWeb.<span style="color: #0000FF;">ID</span><span style="color: #008000;">;</span>
lookupFieldReFetch.<span style="color: #0000FF;">LookupField</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Title&quot;</span><span style="color: #008000;">;</span>
lookupFieldReFetch.<span style="color: #0000FF;">Update</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>This problem still persists in the beta of SharePoint 2010. I hope this will get fixed in the RTM. <a href="http://pholpar.wordpress.com/2010/01/26/updating-sharepoint-lookup-and-user-field-values/">Creating a lookup-field-connection</a> is far more easy by the way …</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2010/02/01/updating-existing-lookup-fields-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Cannot complete this action &#8211; error when adding a ContentType to a list</title>
		<link>http://www.entwicklungsgedanken.de/2008/07/20/cannot-complete-this-action-error-when-adding-a-contenttype-to-a-list/</link>
		<comments>http://www.entwicklungsgedanken.de/2008/07/20/cannot-complete-this-action-error-when-adding-a-contenttype-to-a-list/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 19:21:03 +0000</pubDate>
		<dc:creator>Eric Bartels</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint-Development]]></category>
		<category><![CDATA[ContentType]]></category>
		<category><![CDATA[custom field]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[lookup]]></category>

		<guid isPermaLink="false">http://www.entwicklungsgedanken.de/?p=52</guid>
		<description><![CDATA[Today I got a nice error from my SharePoint development box after I tried to add a certain Content Type to a list. Cannot complete this action. Please try again. at Microsoft.SharePoint.Library.SPRequestInternalClass.AddField&#40;String bstrUrl, String bstrListName, String bstrSchemaXml, Int32 grfAdd&#41; at Microsoft.SharePoint.Library.SPRequest.AddField&#40;String bstrUrl, String bstrListName, String bstrSchemaXml, Int32 grfAdd&#41; Tell me This is an error message [...]]]></description>
			<content:encoded><![CDATA[<p>Today I got a nice error from my SharePoint development box after I tried to add a certain Content Type to a list.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Cannot complete <span style="color: #0600FF;">this</span> action. <span style="color: #0000FF;">Please</span> <span style="color: #0600FF;">try</span> again. <span style="color: #0000FF;">at</span> Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">Library</span>.<span style="color: #0000FF;">SPRequestInternalClass</span>.<span style="color: #0000FF;">AddField</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> bstrUrl, <span style="color: #FF0000;">String</span> bstrListName, <span style="color: #FF0000;">String</span> bstrSchemaXml, Int32 grfAdd<span style="color: #000000;">&#41;</span> 
   at Microsoft.<span style="color: #0000FF;">SharePoint</span>.<span style="color: #0000FF;">Library</span>.<span style="color: #0000FF;">SPRequest</span>.<span style="color: #0000FF;">AddField</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> bstrUrl, <span style="color: #FF0000;">String</span> bstrListName, <span style="color: #FF0000;">String</span> bstrSchemaXml, Int32 grfAdd<span style="color: #000000;">&#41;</span></pre></div></div>

<h3>Tell me</h3>
<p>
This is an error message every developer fells in love with. Its full of nothing&#8230;</p>
<p>
Further analysis revealed that there must be a problem with a custom field definition inside that Content Type. Even more investigation found the culprit.
</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Field</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;LookupMulti&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">DisplayName</span>=<span style="color: #ff0000;">&quot;CustomField&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Required</span>=<span style="color: #ff0000;">&quot;FALSE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Description</span>=<span style="color: #ff0000;">&quot;My custom field&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Group</span>=<span style="color: #ff0000;">&quot;Custom&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">StaticName</span>=<span style="color: #ff0000;">&quot;MyCustomField&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;MyCustomField&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowField</span>=<span style="color: #ff0000;">&quot;Title&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInDisplayForm</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInEditForm</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInNewForm</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInViewForms</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Mult</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Sortable</span>=<span style="color: #ff0000;">&quot;FALSE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Indexed</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">UnlimitedLengthInDocumentLibrary</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">List</span>=<span style="color: #ff0000;">&quot;myList&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">SourceID</span>=<span style="color: #ff0000;">&quot;{31DCE571-D649-41b8-99D7-448F43FCEAC0}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<h3>Conclusion</h3>
<p>
<strong>NEVER</strong> set the attribute <code>Indexed</code> to <code>TRUE</code> when the field is a Lookup-Field that has the <code>Mult</code>-attribute set to <code>TRUE</code>!
</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Field</span> <span style="color: #000066;">Type</span>=<span style="color: #ff0000;">&quot;LookupMulti&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">DisplayName</span>=<span style="color: #ff0000;">&quot;CustomField&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Required</span>=<span style="color: #ff0000;">&quot;FALSE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Description</span>=<span style="color: #ff0000;">&quot;My custom field&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Group</span>=<span style="color: #ff0000;">&quot;Custom&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">StaticName</span>=<span style="color: #ff0000;">&quot;MyCustomField&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;MyCustomField&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowField</span>=<span style="color: #ff0000;">&quot;Title&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInDisplayForm</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInEditForm</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInNewForm</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">ShowInViewForms</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Mult</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Sortable</span>=<span style="color: #ff0000;">&quot;FALSE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">Indexed</span>=<span style="color: #ff0000;">&quot;FALSE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">UnlimitedLengthInDocumentLibrary</span>=<span style="color: #ff0000;">&quot;TRUE&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">List</span>=<span style="color: #ff0000;">&quot;myList&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">SourceID</span>=<span style="color: #ff0000;">&quot;{31DCE571-D649-41b8-99D7-448F43FCEAC0}&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.entwicklungsgedanken.de/2008/07/20/cannot-complete-this-action-error-when-adding-a-contenttype-to-a-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
