<?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>Dynamics NAV Integration &#187; option values</title>
	<atom:link href="http://www.dynamicsnavintegration.dk/tag/option-values/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dynamicsnavintegration.dk</link>
	<description>A site about Dynamics NAV Integration and development</description>
	<lastBuildDate>Wed, 16 Dec 2009 22:08:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Easily changing option values on a field without breaking a sweat</title>
		<link>http://www.dynamicsnavintegration.dk/easily-changing-option-values-on-a-field-without-breaking-a-sweat/</link>
		<comments>http://www.dynamicsnavintegration.dk/easily-changing-option-values-on-a-field-without-breaking-a-sweat/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 21:50:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[codeing tips]]></category>
		<category><![CDATA[dynamics nav]]></category>
		<category><![CDATA[navision]]></category>
		<category><![CDATA[option field]]></category>
		<category><![CDATA[option values]]></category>

		<guid isPermaLink="false">http://www.dynamicsnavintegration.dk/?p=46</guid>
		<description><![CDATA[How many times have we built a table with option fields and then &#8211; six months later &#8211; had to insert option values between the existing option values?
After we insert a new option value, we have to find all code using the options and change the option references, because &#8211; as you know &#8211; it [...]]]></description>
			<content:encoded><![CDATA[<p>How many times have we built a table with option fields and then &#8211; six months later &#8211; had to insert option values between the existing option values?<br />
After we insert a new option value, we have to find all code using the options and change the option references, because &#8211; as you know &#8211; it is the integer value of the option that gets compiled into the object and not the Option::Value part of the field.</p>
<p>Damn.. what can we do to avoid that?<br />
The answer is pretty simple: Start using functions to return the values of the individual option values.</p>
<p><strong>Let&#8217;s say we have a simple table with a option field with three values:</strong><br />
Option1, Option50 and Option100</p>
<p style="text-align: center;"><img class="size-full wp-image-47 aligncenter" title="options" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/options.JPG" alt="options" width="401" height="339" /></p>
<p><strong>Now, create three functions on the table, called:</strong><br />
GetOption1, GetOption50 and GetOption100</p>
<p>Set each function to return an integer. We will be using these functions to return the value of a specific option.</p>
<p style="text-align: center;"><img class="size-full wp-image-48 aligncenter" title="table functions" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/table-functions.JPG" alt="table functions" width="656" height="524" /></p>
<p><strong>Now we are ready to use these new functions in our code:</strong></p>
<p style="text-align: center;"><img class="size-full wp-image-58 aligncenter" title="Getoption code" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/Getoption-code2.JPG" alt="Getoption code" width="497" height="276" /></p>
<p>It is important to use the GetOption-functions everytime and everywhere you would normally use the option value reference (the &#8220;incorrect&#8221; code).</p>
<p><strong>Now comes the part that would usually make us sweat.</strong><br />
Some person says that he wants a new option value &#8211; called Option20 &#8211; and he wants it to be placed between Option1 and Option50 (can&#8217;t argue with that <img src='http://www.dynamicsnavintegration.dk/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> ))<br />
As the nice guys we are, we say &#8220;ok, I will create your option for you&#8221;, knowing we have to go through days of code to find all the places we used Option50 and Option100, because their integer-value have now changed!<br />
Well&#8230; that is no problem anymore <img src='http://www.dynamicsnavintegration.dk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  You&#8217;ve got the Option-functions to do the work.</p>
<p style="text-align: center;">Let&#8217;s insert the option value:<br />
<img class="size-full wp-image-50 aligncenter" title="add option" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/add-option.JPG" alt="add option" width="440" height="335" /></p>
<p><strong>Now let us take a look at our table functions for the option field:</strong></p>
<p style="text-align: center;"><img class="size-full wp-image-51 aligncenter" title="wrong optionvalues" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/wrong-optionvalues.JPG" alt="wrong optionvalues" width="631" height="475" /></p>
<p>As we knew it would happen. The Option20-value is now taking the place of what used to be Option50&#8217;s integer value.<br />
Well, that is ok, because we only need to update the code here in the table. And nowhere else !</p>
<p style="text-align: center;">Update your functions to look like this:<br />
<img class="size-full wp-image-52 aligncenter" title="updated functions" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/updated-functions.JPG" alt="updated functions" width="358" height="233" /></p>
<p>Now, let&#8217;s have a look at the code where we used the function:<br />
Notice how the function-call has not been changed (obviously). But the Option-value reference has been changed, just as in our function, and this would have been the case perhaps hundreds of places around the system.</p>
<p style="text-align: center;"><img class="size-full wp-image-53 aligncenter" title="code after changing values" src="http://www.dynamicsnavintegration.dk/wp-content/uploads/code-after-changing-values.JPG" alt="code after changing values" width="839" height="373" /></p>
<p>I have started to create return-functions for option values everytime I create a new option field and/or add or update values to it.<br />
It is a relief only having to change the code one place <img src='http://www.dynamicsnavintegration.dk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.dynamicsnavintegration.dk/easily-changing-option-values-on-a-field-without-breaking-a-sweat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

