<?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>CleverWorkarounds &#187; EventHandlers</title>
	<atom:link href="http://www.cleverworkarounds.com/category/sharepoint/application-development/eventhandlers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cleverworkarounds.com</link>
	<description>After much frustration, it seems DEFAULT is the way to go...</description>
	<lastBuildDate>Mon, 07 Jun 2010 10:20:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SharePoint Event Handlers &#8211; things to look out for</title>
		<link>http://www.cleverworkarounds.com/2007/11/08/sharepoint-event-handlers-things-to-look-out-for/</link>
		<comments>http://www.cleverworkarounds.com/2007/11/08/sharepoint-event-handlers-things-to-look-out-for/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 12:49:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[EventHandlers]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[document management]]></category>

		<guid isPermaLink="false">http://www.cleverworkarounds.com/2007/11/08/sharepoint-event-handlers-things-to-look-out-for/</guid>
		<description><![CDATA[Just a really quick post &#8211; more event handler stuff to come&#8230; (*sigh* &#8211; I&#8217;m not a coder! Go and read my pal Sezai&#8217;s blog if you want a fix in that area). Situation: I created a list with 2 columns skills discipline Skills was a lookup column against a list of skills. Discipline was [...]<p class="tags">No Tags</p>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-6551570212921028";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_ui_features = "rc:6";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Just a really quick post &#8211; more event handler stuff to come&#8230; (*sigh* &#8211; I&#8217;m not a coder! Go and read my pal <a href="http://sharepoint-sezai-moss-2007.blogspot.com/">Sezai&#8217;s</a> blog if you want a fix in that area).</p>
<p>Situation: I created a list with 2 columns</p>
<ul>
<li>skills  </li>
<li>discipline </li>
</ul>
<p>Skills was a lookup column against a list of skills. Discipline was a single line of text.</p>
</p>
<p><span id="more-252"></span><br />
I then changed my mind and renamed &#8220;skills&#8221; to &#8220;skilltype&#8221; and then created a new &#8220;skills&#8221; column, also a single line of text.
</p>
<p>Net result? Three columns called:</p>
<ul>
<li>skills : single line of text  </li>
<li>skilltype : lookup  </li>
<li>discipline : single line of text </li>
</ul>
<p>I then wrote an event handler that wrote values into skills and discipline columns based on certain conditions.</p>
<p>Here is a code snip of the inherited ItemUpdated() method:</p>
<p><font face="Courier New">listItem["Skills"] = &#8220;Some skill&#8221;;<br />listItem["Disclipline"] = &#8220;some discipline&#8221;;<br />// write the update but do not trigger events<br />this.DisableEventFiring();<br />listItem.SystemUpdate(false);<br />this.EnableEventFiring(); </font></p>
<p>But it did not work. Attached a debugger to my event handler and saw this error:</p>
<p>{&#8220;<strong>Invalid data has been used to update the list item. The field you are </strong><strong>trying to update may be read only</strong>.&#8221;}</p>
<p>What did it mean? READ ONLY? I was writing to the single line of text fields (skill and discipline).</p>
<p>It took me a while to twig to the issue. Renaming a column does not change its &#8216;internal&#8217; name. Using a watch on the list item, the internal field names were:</p>
<ul>
<li>skills  </li>
<li>skills0&nbsp; </li>
<li>discipline </li>
</ul>
<p>Can you see what happened? Renaming &#8216;skills&#8217; to skilltype&#8217; left the <strong>internal</strong> name as &#8216;skills&#8217;. When I added a new &#8216;skills&#8217; column, its internal name had a number appended &#8216;skills0&#8242;.</p>
<p>So if I changed my code to</p>
<p><font face="Courier New">listItem["Skills0"] = &#8220;Some skill&#8221;;</font></p>
<p>It would have solved my problem. Is it clever? No! Better to change my code to refer to the <strong>internal name </strong>of the column. Fortunately, the internal name is exposed via a list&nbsp; item object property.</p>
<p>eg</p>
<p><font face="Courier New">listItem.Fields["Skills"].InternalName </font></p>
<p><font face="tre">returns <strong>&#8220;skills0&#8243;</strong></font></p>
<p>So I modified my lookup to the following:</p>
<p><font face="Courier New">listItem[listItem.Fields["Skills"].InternalName] = &#8220;some skill&#8221;;</font></p>
<p>and the problem was solved.</p>
<p>Moral of the story? Play it safe and <strong>always</strong> use the internal name. Below is the corrected code snippet.</p>
<p><font face="Courier New">listItem[listItem.Fields["Skills"].InternalName] = &#8220;Some Skill&#8221;;<br />listItem[listItem.Fields["Disclipline"].InternalName] = &#8220;Some Discipline&#8221;;<br />// write the update but do not trigger events<br />this.DisableEventFiring();<br />listItem.SystemUpdate(false);<br />this.EnableEventFiring(); </font></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6551570212921028";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_ui_features = "rc:6";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p class="tags">No Tags</p>]]></content:encoded>
			<wfw:commentRss>http://www.cleverworkarounds.com/2007/11/08/sharepoint-event-handlers-things-to-look-out-for/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
