<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.teachmenav.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"><channel><title>Teach Me NAV</title><link>http://www.teachmenav.com/blogs/</link><description>A site to support our book 'Implementing Microsoft Dynamics NAV 2009'.</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>Config File Gotcha</title><link>http://www.teachmenav.com/blogs/dave/archive/2012/02/03/config-file-gotcha.aspx</link><pubDate>Fri, 03 Feb 2012 10:08:44 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:851</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/gotcha_5F00_2FD475BB.jpg"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="gotcha" border="0" alt="gotcha" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/gotcha_5F00_thumb_5F00_123274EF.jpg" width="244" height="184" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I came across something that was a bit weird in an implementation where every user in a Citrix deployed RoleTailored client suddenly connected to the TEST system instead of the LIVE system. I thought I’d share this gotcha to save others from making the same mistake.&lt;/p&gt;  &lt;p&gt;When you start Dynamics NAV 2009’s RoleTailored client, there are a three ways for the client to determine which server to connect to. This is handy to know because most people want to have a live system and a test system shortcut on their desktop and it’s nice to know where you’re going when you start the client.&lt;/p&gt;  &lt;h3&gt;Default ClientUserSettings.config&lt;/h3&gt;  &lt;p&gt;The first method is the default method where the system simply reads your settings from the ClientUserSettings.config file which you can find in &lt;/p&gt;  &lt;p&gt;%ProgramData%\Microsoft\Microsoft Dynamics NAV\&lt;/p&gt;  &lt;p&gt;That’s pretty easy because you don’t need to do anything. The file gets created automatically and if you connect to a different server, the new value gets saved in the file. Not very useful for switching between Live and Test though.&lt;/p&gt;  &lt;h3&gt;Startup .config file&lt;/h3&gt;  &lt;p&gt;This one’s pretty neat. When you start the client, you can add a command line parameter to specify the location of the config file you want to use. The parameter is settings and here’s an example of the shortcut you would need.&lt;/p&gt;  &lt;p&gt;Microsoft.Dynamics.Nav.Client.exe -settings:NavLive.config&lt;/p&gt;  &lt;p&gt;But this is where the gotcha comes in. If you use this settings file to start the client and then connect to a different server, the change gets written back to the config file. That’s not so good when you were trying to use different files to point you to either Live or Test systems. It’s even worse if you are using Citrix to publish the application and every user is updating the same config file. Whilst you don’t get errors, it can be a bit confusing if one user starts up the LIVE system and then jumps to the TEST server which writes the settings back to the config file so the next time a user tries to open the LIVE system they end up in TEST. One solution to this is to make the config files read-only, the other is to use the startup URI.&lt;/p&gt;  &lt;h3&gt;Startup URI&lt;/h3&gt;  &lt;p&gt;I quite like this option for a couple of reasons. First of all, it’s really obvious which system you’re connecting to. Secondly, if you’re connecting to a system that is not your default server (remember the ClientUserSettings.config file?) then the RTC puts up a helpful message telling you. This is great for having two shortcuts that will take you into live or test and it’s not going to mess with your ClientUserSettings.config file either.&lt;/p&gt;  &lt;p&gt;The syntax for the URI allows you to specify which company you want to start in too. You could use this to start up on a specific page if you like.&lt;/p&gt;  &lt;p&gt;Microsoft.Dynamics.Nav.Client.exe &amp;quot;dynamicsnav://NAVSERVER/ServiceName/CompanyName&amp;quot;&lt;/p&gt;  &lt;p&gt;The double quotes are needed if your company name contains spaces.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=851" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>Service Tier and Classic Client Monstrous Nightmare with FieldRef</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/08/12/service-tier-and-classic-client-monstrous-nightmare-with-fieldref.aspx</link><pubDate>Fri, 12 Aug 2011 09:49:27 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:541</guid><dc:creator>David Roys</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;&lt;a href="http://www.daemonsmovies.com/wp-content/uploads/2010/01/monstrous-nightmare-01.jpg"&gt;&lt;img title="Monstrous Nightmare" alt="Monstrous Nightmare" src="http://s1.daemonsmovies.com/mov/up/2010/01/monstrous-nightmare-01-550x319.jpg" width="550" height="319" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I came across an error today that was a monstrous nightmare to track down. First of all, it worked in the Classic client but not in the RoleTailored client. Sigh. Don’t you just hate that? It means going through the pain of debugging the RoleTailored client. &lt;/p&gt;  &lt;p&gt;The error was caused because the FieldRef.Value function for a FieldRef that points to an Option type field returns different values in the Classic client and RoleTailored client.&lt;/p&gt;  &lt;p&gt;If you want proof, try running this Codeunit in both the RTC and Classic.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;// ServiceTier returns different values for FieldRef.Value for Option      &lt;br /&gt;// fields compared to Classic client.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;lRecordRef.OPEN(DATABASE::&amp;quot;Sales Header&amp;quot;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;lFieldRef := lRecordRef.FIELD(1);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;MESSAGE(&amp;#39;ISSERVICETIER=%1\Document Type=%2&amp;#39;,ISSERVICETIER,lFieldRef.VALUE);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;You’ll see the following results. Classic client first…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_2154264A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_75372958.png" width="234" height="175" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then the RoleTailored client…&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_5F010E06.png"&gt;&lt;img style="background-image:none;border-right-width:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_5A1E5A4A.png" width="230" height="135" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;You see that? One returns the string value and the other returns the numeric value for the option string.&lt;/p&gt;  &lt;p&gt;The error we were getting was because the field was being used as an Integer which was throwing a run time error whenever it hit that particular bit of code but only when using the RTC.&lt;/p&gt;  &lt;p&gt;Most of the time in finding this error was in tracking down the line of code that was causing the error to be thrown. I was reading the Statement of Direction for NAV the other day and noticed it suggests we’ll be getting an easy-to-use debugger for the RTC in a future version – I can’t wait! Let’s hope in the future I can say “break on error” and just run my RoleTailored client and find out what the issue is straight away.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=541" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>Creating New Windows Logins in NAV Through a SQL Sproc</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/07/23/creating-new-windows-logins-in-nav-through-a-sql-sproc.aspx</link><pubDate>Sat, 23 Jul 2011 09:02:42 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:531</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;If you’ve been following my on-going battle against the pigs, you’ll be pleased to know that I now have attained three stars on all of the levels in Angry Birds Seasons, Angry Birds, and Angry Birds Rio, so with no more pigs to kill until the next update, I figured I’d write another NAV blog.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_39C3F057.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo" border="0" alt="photo" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_thumb_5F00_0109207D.png" width="244" height="164" /&gt;&lt;/a&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo1_5F00_442478DD.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo1" border="0" alt="photo1" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo1_5F00_thumb_5F00_5F995513.png" width="244" height="164" /&gt;&lt;/a&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo2_5F00_7C52CA28.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo2" border="0" alt="photo2" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo2_5F00_thumb_5F00_1CAA5A1B.png" width="244" height="164" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;One of the reasons I started blogging was to have a place where I could save little gems so they can be easily found later on. One of the directors at Intergen suggested that I blogged the information and then use Google to find it – so that’s what I did. This week I needed to find something I knew I’d done before, but it took me quite a while to track it down, so I figured it’s time to blog the solution so I need never struggle again – and who knows, it may help some of you out too.&lt;/p&gt;  &lt;p&gt;Have you ever had a SQL Backup to restore to a SQL Server that does not allow mixed mode (no database logins, only Windows users) and you need to open the NAV database using NAV but don’t have a login? I created the following SQL code to do this, but you may find it useful to be able quickly add all of the Windows users for your team to a customer’s database. Or how about using the ability to call SQL Stored Procs from NAV (recently blogged about by &lt;a href="http://dynamicsuser.net/blogs/waldo/archive/2011/07/19/net-interop-calling-stored-procedures-on-sql-server-example-1.aspx"&gt;Waldo&lt;/a&gt;) to allow new Windows users to be added to NAV from the RoleTailored client – now that sounds useful!&lt;/p&gt;  &lt;h4&gt;Don’t forget to tell SID&lt;/h4&gt;  &lt;p&gt;NAV stores security for Windows users with a SID which is a funny string that starts with “S” and the first thing I need is something that will give me the SID string for a Windows login.&lt;/p&gt;  &lt;p&gt;Create the following function in the master database.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;USE&lt;/span&gt; master     &lt;br /&gt;GO     &lt;br /&gt;&lt;span style="color:blue;"&gt;CREATE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FUNCTION&lt;/span&gt; fn_SIDToString     &lt;br /&gt;(     &lt;br /&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;(100)     &lt;br /&gt;)     &lt;br /&gt;RETURNS &lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(100)     &lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160; &lt;br /&gt;&amp;#160;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;LEN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;)%4&amp;lt;&amp;gt;0 &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#a9a9a9;"&gt;NULL&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(100)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@i&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INT&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;=&lt;span style="color:red;"&gt;&amp;#39;S-&amp;#39;&lt;/span&gt;+&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;INT&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;,1,1))))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;=&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;-&amp;#39;&lt;/span&gt;+&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;INT&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;,3,6))))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;=9     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@i&lt;/span&gt;=&lt;span style="color:#ff00dc;"&gt;LEN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;&amp;lt;&lt;span style="color:#8b0000;"&gt;@i&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@val&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;BINARY&lt;/span&gt;(4)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@val&lt;/span&gt;=&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@BinSID&lt;/span&gt;,&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;,4)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;=&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;-&amp;#39;&lt;/span&gt;+&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;BIGINT&lt;/span&gt;,&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;REVERSE&lt;/span&gt;(&lt;span style="color:blue;"&gt;CONVERT&lt;/span&gt;(&lt;span style="color:blue;"&gt;VARBINARY&lt;/span&gt;,&lt;span style="color:#8b0000;"&gt;@val&lt;/span&gt;)))))     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;=&lt;span style="color:#8b0000;"&gt;@j&lt;/span&gt;+4     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@StringSID&lt;/span&gt;)     &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;&lt;/code&gt;  &lt;h4&gt;Between a Sproc and a Hard Place&lt;/h4&gt;  &lt;p&gt;Once you have this function, the following stored procedure will create a Windows Login, add it as a windows user, and finally make the user a member of the SUPER role. I’ve hard-coded the database name in this sproc, but you should be able to easily make this a parameter to the sproc if you wish.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;CREATE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;PROCEDURE&lt;/span&gt; [dbo].[proc_CreateNavUser]    &lt;br /&gt;&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;&amp;#160; &lt;span style="color:blue;"&gt;sysname&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160; &lt;br /&gt;&lt;span style="color:blue;"&gt;SET&lt;/span&gt; NOCOUNT &lt;span style="color:blue;"&gt;ON&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(&lt;span style="color:#ff00dc;"&gt;MAX&lt;/span&gt;)    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt; INTEGER    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;=0    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;COUNT&lt;/span&gt;(*)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; master.sys.server_principals    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;)=0    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;=&lt;span style="color:red;"&gt;&amp;#39;use master CREATE LOGIN [&amp;#39;&lt;/span&gt;+&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;] FROM WINDOWS WITH DEFAULT_DATABASE=[master]&amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;EXECUTE&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;COUNT&lt;/span&gt;(*)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].sys.database_principals    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;)=0    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;=&lt;span style="color:red;"&gt;&amp;#39;use [Demo Database NAV (6-0)] CREATE USER [&amp;#39;&lt;/span&gt;+&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;] FOR LOGIN [&amp;#39;&lt;/span&gt;+&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;+&lt;span style="color:red;"&gt;&amp;#39;]&amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;EXECUTE&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@SQL&lt;/span&gt;);    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; CATCH    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; Retval=&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; CATCH    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;=1    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;INSERT&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INTO&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Login]([SID])    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; master.sys.server_principals sp    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; sp.name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;AND&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid) &lt;span style="color:gray;"&gt;NOT&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;IN&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; sid    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Login])    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&lt;span style="color:#008000;"&gt;--Add Roles (SUPER)&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;INSERT&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;INTO&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Access Control]([Login SID],[Role ID],[Company Name])    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid),&lt;span style="color:red;"&gt;&amp;#39;SUPER&amp;#39;&lt;/span&gt;,&lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; master.sys.server_principals sp    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; sp.name=&lt;span style="color:#8b0000;"&gt;@User&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;AND&lt;/span&gt; master.dbo.fn_SIDToString(sp.sid) &lt;span style="color:gray;"&gt;NOT&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;IN&lt;/span&gt;(&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; [Login SID]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt; [Demo &lt;span style="color:blue;"&gt;Database&lt;/span&gt; NAV (6-0)].dbo.[Windows Access Control]    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHERE&lt;/span&gt; [Role ID]=&lt;span style="color:red;"&gt;&amp;#39;BASIC&amp;#39;&lt;/span&gt;)    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt; Retval=&lt;span style="color:#8b0000;"&gt;@RetVal&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; TRY    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt; CATCH    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt; CATCH    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;Enjoy the srpoc. If you do write something that uses this – like a tool to create Windows logins in the RoleTailored client, why not share your solution too?&lt;/p&gt;  &lt;p&gt;Now it’s time to play Cut the Rope.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=531" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>Make me squeal</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/06/20/make-me-squeal.aspx</link><pubDate>Mon, 20 Jun 2011 10:07:14 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:510</guid><dc:creator>David Roys</dc:creator><slash:comments>6</slash:comments><description>&lt;p&gt;If God had wanted me to work, he wouldn’t have given me Angry Birds.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_2A9CFBFF.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="photo" border="0" alt="photo" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/photo_5F00_thumb_5F00_7B1E6765.png" width="244" height="164" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;I figured it was about time I wrote something about Dynamics NAV again, so setting my continuing mission to get three stars on all levels to one side, I’ve finally taken time to pass on a couple of tips around .NET Interop and executing SQL Stored Procs from within NAV (I used to work with someone that pronounced SQL as “Squeal” instead of “Sequel” hence the title of this post).&lt;/p&gt;  &lt;p&gt;Way back in April (wow has it been that long?) I wrote about how you could &lt;a href="http://teachmenav.com/blogs/dave/archive/2011/04/13/execute-sql-command-using-net-interop.aspx"&gt;use .NET Interop to execute SQL commands&lt;/a&gt; using NAV 2009 R2. In my example I executed a simple SQL command and showed how you could parse the dataset returned from the command.&lt;/p&gt;  &lt;p&gt;When I finally came to put this into practice I discovered I had made two errors in my original post which proved to me that I am better at Angry Birds than I am at NAV programming and that, whilst I get many people reading my blog, it’s rare that people actually try out the things I write about.&lt;/p&gt;  &lt;h4&gt;The Host with the Most&lt;/h4&gt;  &lt;p&gt;My first mistake was when I said that I would use the session table to get the machine name of the SQL Server. Wrong! Yes it worked in my example, but that was only because I was running the NAV Server on the same box as the SQL Server. The “Host Name” field on the Session table is the machine name that initiated the connection, so when I moved my code to three tiers it didn’t work. So how do you find the name of the SQL Server you are connecting to?&lt;/p&gt;  &lt;p&gt;Here’s one way that works. I created a view that includes the server name like so:&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;CREATE VIEW [dbo].[SQLConnectionDetails] AS      &lt;br /&gt;SELECT @@ServerName AS [Server Name],       &lt;br /&gt;DB_NAME() AS [Database Name]&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Then I made a linked table in NAV over the top of the view. Now I can use SQLConnectionDetails.[Server Name] as part of my connect string. Phew!&lt;/p&gt;  &lt;h4&gt;Enum Nuts&lt;/h4&gt;  &lt;p&gt;My next mistake was when I assumed that the enumerated value for a SQL Stored Proc command type was 1. Wrong again! I’d made that assumption because the documentation on the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.commandtype.aspx"&gt;properties of the CommandType&lt;/a&gt; showed a table with three options then they would be numbered 0, 1, and 2. Finding the correct integer value was not easy but in the end it was Waldo to the rescue. I knew I had read &lt;a href="http://dynamicsuser.net/blogs/waldo/archive/2011/04/19/nav-2009-r2-net-interop-using-enumerations-part-1.aspx"&gt;a post from Waldo about using enumerated types in .NET interop&lt;/a&gt; so I used his code to parse the value. Here’s how to do it for the SQL command type.&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;//Set the command type as StoredProcedure.      &lt;br /&gt;dnCommandType := dnSQLCommand.CommandType;       &lt;br /&gt;dnSQLCommand.CommandType := dnCommandType.Parse(dnCommandType.GetType(),&amp;#39;StoredProcedure&amp;#39;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Much better to have this code that is self-documenting than put in the numeric values but if you’re feeling lazy, the number values are: Text is 1, StoredProcedure is 4 and TableDirect is 512.&lt;/p&gt;  &lt;h4&gt;Pulling my heir out&lt;/h4&gt;  &lt;p&gt;My final problem (not a mistake this time but something I thought I would pass on) was when I came to try to add parameters to my stored procedure I hit a problem I thought I couldn’t get past.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_7B5AEA9A.png"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_55F0F72C.png" width="424" height="232" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I could not instantiate a Parameter collection on my SQL Command because NAV thought for some crazy reason that there were two Parameters properties. Now .NET (as far as I know) does not support overloaded properties so this is not possible and I can only put it down to a bug in the R2 release. I have reported this to the product team and I am assured this problem will be fixed in a later release.&lt;/p&gt;  &lt;p&gt;So if I can’t add parameters to my stored proc, how can I get around it? My solution was to instantiate a variable of type System.Data.Common.DbCommand which the SQLCommand class inherits. I could then use the Parameters property of the Common.DbCommand and assign this to my SQLParameterCollection. Don’t you just love object oriented?&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;dnCommonDBCommand := dnSQLCommand;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;// Need to use the dnCommonDBCommand.Parameters becuase the SQLCommand.Parameters gets confused in the R2 Release      &lt;br /&gt;dnSQLParameterCollection := dnCommonDBCommand.Parameters();       &lt;br /&gt;dnSQLParameterCollection.Add(pParameterName,pParameterValue);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;Now I have instantiated my SQLParameterCollection, I can use the Add method and add my new parameters.&lt;/p&gt;  &lt;p&gt;Well that’s it for now. Time to try to crack three stars on level 10. Die pigs, die!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=510" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>20-30% Discount on Dynamics Books During May 2011</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/05/17/20-30-discount-on-dynamics-books-during-may-2011.aspx</link><pubDate>Tue, 17 May 2011 07:25:11 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:509</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://www.packtpub.com/article/exclusive-offer-microsoft-dynamics-books"&gt;&lt;img border="0" src="http://www.packtpub.com/sites/default/files/Dynamics%20May%20Logo.png" width="543" height="216" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Those people at PACKT have been busy making more and more books on Dynamics covering GP 2010, NAV 2009, AX 2009, and Sure Step, so whichever flavour of Dynamics you prefer, there’s something for you to get your teeth into.&lt;/p&gt;  &lt;p&gt;To celebrate the recent publication of the &lt;a href="https://www.packtpub.com/microsoft-dynamics-gp-2010-reporting/book?utm_source=microsoft_dynamics_may&amp;amp;utm_medium=campaign_page&amp;amp;utm_term=Microsoft%2BDynamics%2BGP%2B2010%2BReporting%3A%2BRAW&amp;amp;utm_campaign=enterprise"&gt;Microsoft Dynamics GP 2010 Reporting&lt;/a&gt; book, PACKT has announced a series of attractive discounts on their Dynamics books:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Buy any Microsoft Dynamics printbook and get 20% off &lt;/li&gt;    &lt;li&gt;Buy any Microsoft Dynamics eBook and get 30% off &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;So if you’ve been waiting to buy a copy of the book I wrote with Vjeko (&lt;a href="http://www.packtpub.com/implementing-microsoft-dynamics-nav-2009/book/mid/190109h5mbvn"&gt;Implementing Microsoft Dynamics NAV 2009&lt;/a&gt;) now’s your chance to order your copy and save some money. Our book has funny references and quotes, a comparison between the Chart of Accounts and a Hippo’s Bottom, and a section on how to perform analysis and design that uses super villains from a comic book as the users. There’s even some sensible stuff in there too. OK I’ll admit that some of the details about Web services is old news now and was written for NAV 2009, and there’s nothing on the things that came with SP1 and R2, but it’s a good fun read and, who knows, you might learn a thing or two along the way.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=509" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Book+News/default.aspx">Book News</category></item><item><title>Execute SQL Command using .NET Interop</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/04/13/execute-sql-command-using-net-interop.aspx</link><pubDate>Wed, 13 Apr 2011 10:12:00 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:508</guid><dc:creator>David Roys</dc:creator><slash:comments>2</slash:comments><description>&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_7D0DD8E7.png"&gt;&lt;img height="44" width="126" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_10BAC27C.png" alt="image" border="0" title="image" style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;OK, I&amp;rsquo;ll admit it, I&amp;rsquo;m obsessed with the .NET Interop features in NAV 2009 R2. My last two blog posts have been on this and now here&amp;rsquo;s another one.&lt;/p&gt;
&lt;p&gt;Today I wanted to see if I could use the .NET Interop features in NAV 2009 R2 to execute a SQL Stored Procedure and extract the results. I know you can do this using COM, but I figured it would be fun to try this using .NET. The great thing about .NET is it&amp;rsquo;s so well documented. My starting point for this exercise was to search for executing a SQL Stored Procedure in C# which gave me this post &lt;a href="http://support.microsoft.com/kb/320916" title="http://support.microsoft.com/kb/320916"&gt;http://support.microsoft.com/kb/320916&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I then used that to figure out which .NET classes I needed to write my C/AL code.&lt;/p&gt;
&lt;p&gt;In this sample I&amp;rsquo;m using a SQL Command rather than a stored procedure call, but that&amp;rsquo;s just so you can try it for yourself easily without needing to create a stored procedure. It&amp;rsquo;s easy enough to change it to a stored procedure and I left the code in there but commented out.&lt;/p&gt;
&lt;p&gt;The worst thing about using this stuff is the number of variables you need to define. I put this down to the fact that the .NET interop does not support multi-dotting where I can write things like foo.bar.thing(). I&amp;rsquo;m hoping we&amp;rsquo;ll get multi-dotting in a future version.&lt;/p&gt;
&lt;p&gt;So for this to work, you&amp;rsquo;ll need to create a whole bunch of variables. Rather than list them here, I&amp;rsquo;ve included a text export of my Codeunit as a download.&lt;/p&gt;
&lt;p&gt;The example is really simple. I select the names of the companies in the current database and display the Row Count and then the first 5 company names.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s my code:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;//Use the session table to find the database and server name for the current connection &lt;br /&gt;Session.SETRANGE(&amp;quot;My Session&amp;quot;,TRUE); &lt;br /&gt;Session.FINDFIRST;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Open a connection using windows authentication to the current session database and server &lt;br /&gt;dnSQLConnection := dnSQLConnection.SqlConnection(&amp;#39;server=&amp;#39;+Session.&amp;quot;Host Name&amp;quot;+&amp;#39;;&amp;#39;+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;database=&amp;#39;+Session.&amp;quot;Database Name&amp;quot;+&amp;#39;;&amp;#39;+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;Trusted_Connection=sspi&amp;#39;);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a DataAdapter &lt;br /&gt;dnSQLDataAdapter := dnSQLDataAdapter.SqlDataAdapter();&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;{ &lt;br /&gt;// Example of using a stored procedure and not a select string&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a SQL Command on our connection &lt;br /&gt;dnSQLCommand := dnSQLCommand.SqlCommand(&amp;#39;myStoredProc&amp;#39;,dnSQLConnection); &lt;br /&gt;//Set the command type as StoredProcedure. &lt;br /&gt;dnSQLCommand.CommandType := 1; &lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a SQL Command on our connection &lt;br /&gt;dnSQLCommand := dnSQLCommand.SqlCommand(&amp;#39;select * from Company&amp;#39;,dnSQLConnection);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Assign the SQL command as the select command on my data adapter. &lt;br /&gt;dnSQLDataAdapter.SelectCommand := dnSQLCommand;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Create a dataset &lt;br /&gt;dnDataSet := dnDataSet.DataSet;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Fill the dataset by executing my command on the data adapter. &lt;br /&gt;dnSQLDataAdapter.Fill(dnDataSet);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Get the collection of tables &lt;br /&gt;dnDataTableCollection := dnDataSet.Tables;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Get the first table &lt;br /&gt;dnDataTable := dnDataTableCollection.Item(0);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;//Get the collection of rows &lt;br /&gt;dnDataRowCollection := dnDataTable.Rows;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;MESSAGE(&amp;#39;There are %1 Rows&amp;#39;, dnDataRowCollection.Count);&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;currentRow := 0;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family:Courier New;"&gt;REPEAT &lt;br /&gt;&amp;nbsp; //Get the currentRow row &lt;br /&gt;&amp;nbsp; dnDataRow := dnDataRowCollection.Item(currentRow); &lt;br /&gt;&amp;nbsp; MESSAGE(&amp;#39;%1&amp;#39;,dnDataRow.Item(1)); &lt;br /&gt;&amp;nbsp; currentRow += 1; &lt;br /&gt;UNTIL (currentRow = 5) OR (currentRow = dnDataRowCollection.Count); &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;"&gt;//Tidy up &lt;br /&gt;dnSQLDataAdapter.Dispose(); &lt;br /&gt;dnSQLConnection.Close();&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;In a New Zealand demo database this gives the following messages:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML851fe47_5F00_7AF0DA1E.png"&gt;&lt;img height="134" width="193" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML851fe47_5F00_thumb_5F00_55F319A5.png" alt="SNAGHTML851fe47" border="0" title="SNAGHTML851fe47" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML8524d6f_5F00_18EEE813.png"&gt;&lt;img height="133" width="244" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML8524d6f_5F00_thumb_5F00_140C3457.png" alt="SNAGHTML8524d6f" border="0" title="SNAGHTML8524d6f" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML85295e4_5F00_2510623A.png"&gt;&lt;img height="133" width="244" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/SNAGHTML85295e4_5F00_thumb_5F00_4453090D.png" alt="SNAGHTML85295e4" border="0" title="SNAGHTML85295e4" style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can download the Codeunit &lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/Call-SQL-from-.NET.txt"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=508" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>.NET Interop—I’m Lovin’ It!</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/02/16/net-interop-i-m-lovin-it.aspx</link><pubDate>Wed, 16 Feb 2011 08:33:37 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:506</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;If this was a blog about grammar, I might be asking whether a verb like “to love” can be conjugated in a progressive tense to give us the phrase “I’m Lovin’ It”. But it’s not, it’s a blog about Dynamics NAV and I’m writing about .NET Interop in Dynamics NAV 2009 R2 which has got to be &lt;em&gt;the&lt;/em&gt; coolest feature for NAV ever!&lt;/p&gt;  &lt;p&gt;Let’s assume that you’re into Dynamics NAV and not dynamic verbs. The question I’m really asking here is how do you find the temporary path in Dynamics NAV? Easy, I hear your shout. You just use ENVIRON(‘TEMP’);&lt;/p&gt;  &lt;p&gt;Aha, but what if you’re using the RoleTailored client and you want to find the temp directory on the client? If you try using the ENVIRON command you’ll get the following error message:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_33B9D4BC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_24A2F5E2.png" width="244" height="112" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Previously I solved this problem in quite a convoluted way. I created a temporary file (albeit an empty one) in the temporary path on the NAV Server, then I transferred it to the client using the&amp;#160; magic path, then I found the path of the location of the file where it got transferred to.&lt;/p&gt;  &lt;p&gt;Does that sound crazy? Take a look at the ClientTempFileName() function in the 3-Tier Automation Mgt. codeunit if you don’t believe me. I used that function to get a client temporary file and then used&amp;#160; the Path function to find the client temporary file path.&lt;/p&gt;  &lt;p&gt;But now with the .NET Interop there is a better way.&lt;/p&gt;  &lt;p&gt;Simply create a local variable of type DotNet and Subtype &amp;#39;mscorlib&amp;#39;.System.Environment. Make sure you bring up the properties of the variable and set the RunOnClient property to Yes.&lt;/p&gt;  &lt;p&gt;Now you can write code like this:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;IF ISSERVICETIER THEN     &lt;br /&gt;&amp;#160; MESSAGE(&amp;#39;Temp is %1&amp;#39;,dnEnvironment.GetEnvironmentVariable(&amp;#39;temp&amp;#39;))      &lt;br /&gt;ELSE      &lt;br /&gt;&amp;#160; MESSAGE(&amp;#39;Temp is %1&amp;#39;,ENVIRON(&amp;#39;temp&amp;#39;));      &lt;br /&gt;EXIT;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Aaah. I’m Lovin’ It!&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;P.S. If you’re more interested in grammar than Dynamics NAV, check out &lt;a title="http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx" href="http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx"&gt;http://grammar.quickanddirtytips.com/im-loving-it-grammar.aspx&lt;/a&gt; to find out why McDonald’s slogan is such bad grammar.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=506" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>Regular Expressions in NAV</title><link>http://www.teachmenav.com/blogs/dave/archive/2011/02/02/regular-expressions-in-nav.aspx</link><pubDate>Wed, 02 Feb 2011 07:32:55 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:458</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;A friend of mine recently asked if there was a standard NAV function to find the first alphabetical character in a string. STRPOS comes close but you can&amp;#39;t say &amp;quot;tell me the first position for any one of these characters in this string&amp;quot; because it looks for an exact match of the substring and not any character from the substring.&lt;/p&gt;  &lt;p&gt;The AL code to do this isn&amp;#39;t hard but I figured this was a perfect excuse to play with the new .NET Interop feature in NAV 2009 R2.&lt;/p&gt;  &lt;p&gt;With the release of NAV 2009 R2, we have the ability to use the . NET Framework directly from within AL code. Now we can use simple .NET classes to do things with strings that previously required several lines of code. I&amp;#39;m thinking of regular expressions of course.&lt;/p&gt;  &lt;p&gt;The regular expression for any character between A and Z or a and z is [A-Z,a-z].&lt;/p&gt;  &lt;p&gt;I created a function in a Codeunit called RegExFind that takes two parameters (a string to be search and a string containing the regular expression to match on). It returns an Integer which is the matching position of the first matching character (it returns 0 if it doesn&amp;#39;t find a match).&lt;/p&gt;  &lt;p&gt;To run the code, you need to add the Codeunit to a RoleTailored MenuSuite as .NET Interop only works on the service tier. You could put this code in a button on a page too, if you wish.&lt;/p&gt;  &lt;p&gt;Here is the function:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;RegExFind(SearchString : Text[250];RegEx : Text[250]) : Integer     &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;dnMatch := dnRegEx.Match(SearchString,RegEx);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;IF dnMatch.Success THEN      &lt;br /&gt;&amp;#160; EXIT(dnMatch.Index+1)      &lt;br /&gt;ELSE      &lt;br /&gt;&amp;#160; EXIT(0);      &lt;br /&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;In my Function I have the following local variables:&lt;/p&gt;  &lt;table border="1" cellspacing="0" cellpadding="2" width="733"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="128"&gt;&lt;strong&gt;Name&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="128"&gt;&lt;strong&gt;DataType&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="475"&gt;&lt;strong&gt;Subtype&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="125"&gt;dnRegEx&lt;/td&gt;        &lt;td valign="top" width="126"&gt;DotNet&lt;/td&gt;        &lt;td valign="top" width="480"&gt;&amp;#39;System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;#39;.System.Text.RegularExpressions.Regex&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="123"&gt;dnMatch&lt;/td&gt;        &lt;td valign="top" width="126"&gt;DotNet&lt;/td&gt;        &lt;td valign="top" width="484"&gt;&amp;#39;System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089&amp;#39;.System.Text.RegularExpressions.Match&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Notice that we return the Index +1 (as in .NET all arrays start at 0 where in AL they start at 1).&lt;/p&gt;  &lt;p&gt;The code to call the function is shown here:&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;SearchString := &amp;#39;1234 Lines of Code&amp;#39;;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;FoundPos := RegExFind(SearchString,&amp;#39;[a-z,A-Z]&amp;#39;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;IF FoundPos &amp;gt; 0 THEN     &lt;br /&gt;&amp;#160; MESSAGE (&amp;#39;Found %1 at position %2 in %3&amp;#39;,COPYSTR(SearchString,FoundPos,1),FoundPos,SearchString);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;&lt;font face="Courier New"&gt;SearchString := &amp;#39;Now I look for 1 or 2 numbers.&amp;#39;;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;FoundPos := RegExFind(SearchString,&amp;#39;[0-9]&amp;#39;);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;IF FoundPos &amp;gt; 0 THEN     &lt;br /&gt;&amp;#160; MESSAGE (&amp;#39;Found %1 at position %2 in %3&amp;#39;,COPYSTR(SearchString,FoundPos,1),FoundPos,SearchString);&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;As you would expect, when I run this Codeunit from my RoleTailored client, I get the following output:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_198D1D0F.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_38CFC3E2.png" width="330" height="134" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_7C37C544.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_306BEE8B.png" width="397" height="134" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;The only problem with the new .NET Interop is knowing what&amp;#39;s out there in the framework. The chances are, there&amp;#39;s something to handle your requirement and the good news is there&amp;#39;ll be plenty of examples of how to use it - just as long as you can translate the C# code into an AL equivalent.&lt;/p&gt;  &lt;p&gt;This simple example is just the tip of the iceberg for what you can do with regular expressions. Wouldn&amp;#39;t it be nice to use regular expressions to validate user input?&lt;/p&gt;  &lt;p&gt;Have you got any favourite .NET tricks that you’d like to do in AL code?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=458" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+R2/default.aspx">NAV 2009 R2</category></item><item><title>Book Review: Microsoft Dynamics NAV Administration</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/12/31/book-review-microsoft-dynamics-nav-administration.aspx</link><pubDate>Fri, 31 Dec 2010 03:18:03 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:456</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;table border="0" cellspacing="0" cellpadding="2" width="551"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="213"&gt;&lt;a href="https://www.packtpub.com/microsoft-dynamics-nav-administration/book"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="8761EN_Microsoft Dynamics NAV Administration" border="0" alt="8761EN_Microsoft Dynamics NAV Administration" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/8761EN_5F00_Microsoft_2D00_Dynamics_2D00_NAV_2D00_Administration_5F00_37646415.jpg" width="198" height="244" /&gt;&lt;/a&gt;&lt;/td&gt;        &lt;td valign="top" width="336"&gt;&lt;strong&gt;Authors:&lt;/strong&gt; Sharan Oberoi, Amit Sachdev           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Publisher:&lt;/strong&gt; PACKT           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;ISBN:&lt;/strong&gt; 978-1-84719-876-1           &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Published:&lt;/strong&gt; September 2010&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Once upon a time you couldn’t get books on Dynamics NAV for love nor money, then in October 2007 PACKT published David Studebaker’s book &lt;em&gt;Programming Microsoft Dynamics NAV&lt;/em&gt;. I read David’s book and wrote a review (&lt;a title="http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html" href="http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html"&gt;http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html&lt;/a&gt;) and became inspired to co-write my own book on Dynamics NAV.&lt;/p&gt;  &lt;p&gt;Things are very different now; there are loads of books on Dynamics NAV for everyone covering Programming, Implementing, Designing, Cooking, and now &lt;a href="https://www.packtpub.com/microsoft-dynamics-nav-administration/book"&gt;Administrating&lt;/a&gt;. OK so maybe not cooking, but there is a programming cookbook which I reviewed on this blog (&lt;a title="http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx" href="http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx"&gt;http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;With so many books around, you may be wondering what this new book from Canadian-based authors Sharan and Amit offers that can’t be found elsewhere. This is the first book on Dynamics NAV that appears to be aimed squarely at beginners. I can see how this book may appeal to someone who has landed a job with a company that uses Dynamics NAV and wants a quick guide to some of the capabilities of the product and a high level view of how to perform some admin tasks. The book covers essential tasks like creating new users and assigning security permissions, taking backups and restoring backups, and importing programming modifications from a FOB file delivered by a partner. This is all useful stuff for anyone working as a system administrator for NAV. There are only 175 pages (not including index and preface) spread over nine chapters with lots of screen images so it’s not going to take you long to read this.&lt;/p&gt;  &lt;p&gt;According to the blurb on the PACKT site, “this book is a tutorial guide that illustrates the steps needed to install, configure, deploy, and administer Dynamics NAV”. Dynamics NAV is a very complex system and this book does not even begin to cover all of the various tasks needed to install and configure the system, but if you need to know how to run the install wizard, this book will show you how to do it and give you a bit more of an idea of what is happening. There are some fundamental things missing, like how to configure the Service Principal Names (SPNs) needed to allow the system to run on three separate machines (SQL Server, NAV Server, and Client); however, this topic is well covered in the MSDN Library (&lt;a title="http://msdn.microsoft.com/en-us/library/dd301254.aspx?ppud=4" href="http://msdn.microsoft.com/en-us/library/dd301254.aspx?ppud=4"&gt;http://msdn.microsoft.com/en-us/library/dd301254.aspx?ppud=4&lt;/a&gt;).&lt;/p&gt;  &lt;p&gt;There was an interesting section on virtualisation, but like the rest of the book, it doesn’t go in to a great amount of detail. I guess for an administrator, this lack of detail is a good thing as you don’t want to get bogged down with pages and pages of technicalities, but you’re not going to be able to fly solo on most of these topics without getting help from a partner or reading some of the other material available through Customer Source, the online help, or the MSDN library.&lt;/p&gt;  &lt;p&gt;Coincidentally, I used to work with one of the authors, Sharan Oberoi, when he worked for Ernst and Young in New Zealand, so I feel I need to focus on the positive aspects of this book and not dwell on the areas where, for me, it fell short. At times I felt as though I was reading a giant product brochure from Microsoft about Dynamics NAV, but on a more positive note, this book provides a good introduction to a wide variety of topics that may be of interest to a systems administrator.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=456" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Book+Review/default.aspx">Book Review</category></item><item><title>Is there anybody out there?</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/11/28/is-there-anybody-out-there.aspx</link><pubDate>Sat, 27 Nov 2010 22:07:22 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:450</guid><dc:creator>David Roys</dc:creator><slash:comments>5</slash:comments><description>&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/Visual_2D00_Studio_2D00_2010_2D00_Ultimate_5F00_6C1C17EC.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:block;float:none;border-top:0px;border-right:0px;padding-top:0px;" title="Visual Studio 2010 Ultimate" border="0" alt="Visual Studio 2010 Ultimate" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/Visual_2D00_Studio_2D00_2010_2D00_Ultimate_5F00_thumb_5F00_21D15D47.png" width="240" height="159" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Way way back in July I ran a competition to give away 2 Microsoft Visual Studio 2010 Ultimate with MSDN subscription cards. I said I would announce the winners in September, but didn’t. You see the thing is, the response was pathetic. Only one entry who is of course now the proud owner of an MSDN subscription worth several thousand dollars.&lt;/p&gt;  &lt;p&gt;I’ve got one more subscription card still to give away, so the first person to tell me which Pink Floyd song includes the lyrics “Is there anybody out there?” gets it.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The 12-month MSDN subscription has some restrictions with it being a NFR version (technical support benefits and MSDN Magazine are not included, and all software benefits, including Microsoft Office 2010 products, are for development and test purposes only).&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The subscriptions need to be registered within 180 days of when I received them (that means you have until around the end of December 2010 to register, but I won’t be responsible for you neglecting to register—if you win a prize, register it straight away).&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=450" width="1" height="1"&gt;</description></item><item><title>Book Review: Microsoft Dynamics NAV 2009 Programming Cookbook</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/11/28/book-review-microsoft-dynamics-nav-2009-programming-cookbook.aspx</link><pubDate>Sat, 27 Nov 2010 21:34:18 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:449</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;table border="0" cellspacing="0" cellpadding="2" width="637"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;p&gt;&lt;a href="http://link.packtpub.com/36XzE2" target="_blank"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="0943ENEN_MockupCover%20Coock%20book_0" border="0" alt="0943ENEN_MockupCover%20Coock%20book_0" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/0943ENEN_5F00_MockupCover20Coock20book_5F00_0_5F00_30245DB5.jpg" width="198" height="244" /&gt;&lt;/a&gt;&lt;/p&gt;       &lt;/td&gt;        &lt;td valign="top" width="435"&gt;&lt;strong&gt;Author&lt;/strong&gt;: Matt Traxinger          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Publisher&lt;/strong&gt;: PACKT          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;ISBN&lt;/strong&gt;: 978-1-84968-094-3          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Published&lt;/strong&gt;: October 2010&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;Long ago when I was co-writing &lt;i&gt;Implementing Microsoft Dynamics NAV 2009&lt;/i&gt; one of my colleagues said to me, “You don’t want to write a book like that, you want to write a NAV cookbook.” I must admit I hadn’t read any programming cookbooks and didn’t know what he was talking about so I just smiled and nodded reassuringly before totally ignoring him.&lt;/p&gt;  &lt;p&gt;Then, lo and behold, along comes a request from PACKT asking me to do the technical reviewing of a new book being written by Matt Traxinger called &lt;i&gt;&lt;a href="http://link.packtpub.com/36XzE2" target="_blank"&gt;Microsoft Dynamics NAV 2009 Programming Cookbook&lt;/a&gt;&lt;/i&gt;. Now if there’s one thing I like, it’s getting free stuff, and I remember from my authoring of &lt;i&gt;Implementing&lt;/i&gt; that the technical reviewers get a free book or two. I also remembered that the work of the technical reviewers on our book helped us (me and Vjeko) immensely and so I looked forward to helping Matt out if I could. Today I received my shiny new copy of Matt’s book (free stuff is so cool, heh, heh, heh) and I figured it was time I wrote something about it on my blog.&lt;/p&gt;  &lt;p&gt;So who is Matt Traxinger? I thought I recognised the name, but had never dealt with him directly as far as I was aware. He’s on dynamicsuser.net under the user name MattTrax and he’s made more than 500 posts. Chances are he’s helped me out more than a couple of times. If you want the bio from the book, you can &lt;a href="https://www.packtpub.com/authors/profiles/matt-traxinger"&gt;read all about Matt here&lt;/a&gt;. I can tell you that after working on reviewing this book he seems like a really great guy and when it comes to knowing about NAV well…&lt;/p&gt;  &lt;p&gt;This book is packed full of useful stuff. I’ve been doing NAV programming for quite a while now and I know a thing or two, but I found plenty in the book that I could use straight away in my day to day work. The book is divided into 112 recipes that go from the noddy stuff (like basic building blocks of programming NAV) to pretty advanced topics that require creating .NET controls and automations using Visual Studio. It seems like there is no problem too big for Matt. If NAV can’t do it, he rolls up his sleeves, cranks up Visual Studio and finds a solution. That was the thing I loved about this book. Matt has a great attitude to working with NAV and shows what can be done if you’re prepared to think outside the box.&lt;/p&gt;  &lt;p&gt;I loved this book. There’s something in it for everyone. The recipes are fun-sized morsels of knowledge and you can dib in and out when you need to solve a particular problem, or you can start from the beginning and work your way through if you just want to learn as much as you can.&lt;/p&gt;  &lt;p&gt;There are plenty of sources of knowledge on NAV now including various books, blogs, and online articles; if you’re a completely stingy git, you may prefer to spend your time trawling through forums and trying lots of things rather than shelling out for Matt’s book. I know I’d rather save my time and go straight to one reference where I can get an easy step-by-step guide on how to get past my current problem and then move on.&lt;/p&gt;  &lt;p&gt;If you program NAV, you need this book. Well done Matt!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=449" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Book+Review/default.aspx">Book Review</category></item><item><title>Creating a view across all companies–part 3</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/08/29/creating-a-view-across-all-companies-part-3.aspx</link><pubDate>Sun, 29 Aug 2010 02:31:22 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:447</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;img style="margin:5px;display:inline;" align="left" src="http://i19.photobucket.com/albums/b160/psuedoemo/bear-sitting-picnic-table.jpg" width="200" height="200" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;This is the final part in a three part series of blog posts. In &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx"&gt;part 1&lt;/a&gt; I wrote about how you could use a couple of fields in the $ndo$dbproperty table to create a ConvertInvalidChars() function that would turn your NAV company name into the prefix for the table name as it is used in the SQL database. Then in &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2010/08/22/creating-a-view-across-all-companies-part-2.aspx"&gt;part 2&lt;/a&gt; I showed you how to create a SQL script that would dynamically create your view for all companies that exist in the database. In this final part, I’m going to show you how to link the view to a NAV table and talk about some of the things to watch out for.&lt;/p&gt;  &lt;p&gt;If you’ve followed the previous parts, you should now have a SQL view called Company Vendor that contains every field from the Vendor table in NAV plus a new field called Company Name that contains the company name.&lt;/p&gt;  &lt;h2&gt;Linked Tables&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_52EA26FE.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;margin:5px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" align="right" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_65DAE243.png" width="363" height="275" /&gt;&lt;/a&gt;&lt;/h2&gt;  &lt;p&gt;NAV has a neat property on the table definition that allows you to say a table is linked to a view in the database that has the same name as the table name. You can see this property by bringing up the properties for the table and looking at Linked Object. In the next image, you can see the property for my table 50001 is set to Yes. There is another property called LinkedInTransaction and the use of this has often been mysterious, I think because the online help definition is so poor and also because it is very rare for me to try to update the data in the linked object. According to a &lt;a href="http://dynamicsuser.net/forums/p/24642/131913.aspx"&gt;dynamicsuser.net post&lt;/a&gt; from Dean McCrae, when you have LinkedInTransaction set to No, NAV uses a separate connection and separate transaction for accessing the linked tables. This means that if your main connection rollsback due to an error, it does not affect the transaction performed for the linked object. The purpose of LinkedInTransaction is to make the transactions performed on the linked objects isolated from the main transaction. So it only matters if you plan to allow transactions such as inserts, updates and deletes on this linked object. In this example we are not allowing that.&lt;/p&gt;  &lt;h2&gt;Creating the Linked Table&lt;/h2&gt;  &lt;p&gt;I have found the quickest way to create my linked table is to edit my original table (in this case the Vendor table) and then edit the properties to change the ID, Name and set the LinkedObject property to Yes and DataPerCompany to no. I can then save my table. Since my view already exists, it all gets plumbed up correctly. I can now run my table and I see data from both of my companies – but unfortunately I can’t see the company name, and that is because I haven’t added the Company Name field. When I edit my table and add the new Company Name field, I come across the first of the problems with this simple technique. I get a message telling me that “The Record variable must belong to 23 and not to 50001”. The reason for this error is that there is programming logic attached to various triggers on the table that is expecting the table to be the Vendor table (23) and not our new Company Vendor table (50001). In short, you are going to need to remove all programming triggers from your table definition. You can do this easily by pressing Ctrl+S to save the table, the error message will be displayed and when you click OK, you will be taken to the code editing window. Now simply press Ctrl+Home to get to the start of the code, hold the Shift key down and press Ctrl+End so that all text in all programming triggers is selected. Then press delete. Finally, call up the Global variables window, open the Functions tab and select all of the functions, then delete. This will remove those functions that get left behind as empty functions when we deleted the code.&lt;/p&gt;  &lt;h2&gt;Gotchas&lt;/h2&gt;  &lt;p&gt;Although it was really easy for me to create my linked table by saving the existing table, there are a couple of things wrong with this. First of all, I need to remember to remove the programming code from the table, otherwise bad things could happen unexpectedly (such as data being updated in related tables on validates). The other issue relates to FlowFields. The system does not complain about the flowfield definitions in the table but you should be careful of these. The flow fields (such as Balance) are used to sum up the remaining amount on the Vendor Ledger entries for this Vendor, but the system does not know that the Vendor actually exists in a different company. If you are lucky, the flow fields will simply display 0. If you are unlucky there will be a Vendor with the same code in different companies and as a result, you will see a value that is related to the wrong company. My advice to you is to remove the flowfields and flowfilters from your table definition. On the vendor table this is 56 different fields. It’s at this point that I’m starting to wonder whether I actually saved any time by copying the existing table. It’s not actually that hard to go down the list of fields and delete the ones you don’t think you’ll need. You may find that when you delete certain fields from the table, the system complains that the fields are used in an active key. This is a good reason to delete the keys from the table definition too and make the primary key “Company Name”, “No.”.&lt;/p&gt;  &lt;h2&gt;Making the Page&lt;/h2&gt;  &lt;p&gt;My final step is to make a page over my new table. Remember to make the page non-editable and to say Insert Allowed, Delete Allowed and Modify Allowed = No. We don’t want someone accidentally deleting records from the view, because this will delete the actual records from the linked tables (and I have found that it doesn’t care what the underlying table is, even tables like the General Ledger Entry table which you wouldn’t normally be allowed to delete from using a regular user’s license). Here’s a picture of my final page showing how I can search across multiple companies for a specific vendor name.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_0445232D.png"&gt;&lt;img style="background-image:none;border-bottom:0px;border-left:0px;padding-left:0px;padding-right:0px;display:inline;border-top:0px;border-right:0px;padding-top:0px;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_77D70003.png" width="644" height="433" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Have fun with your linked tables.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=447" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category></item><item><title>Creating a view across all companies—part 2</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/08/22/creating-a-view-across-all-companies-part-2.aspx</link><pubDate>Sun, 22 Aug 2010 04:12:14 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:443</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://serverperformancemonitor.com/images/magnifying-glass.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;margin:0px 4px 4px 0px;display:inline;border-top:0px;border-right:0px;" border="0" align="left" src="http://ts3.mm.bing.net/images/thumbnail.aspx?q=202861448386&amp;amp;id=b1c9a2ea4da7eb04c8bb18b4ca57a871&amp;amp;url=http%3a%2f%2fserverperformancemonitor.com%2fimages%2fmagnifying-glass.jpg" width="160" height="120" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;In &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx" target="_blank"&gt;last week’s post&lt;/a&gt; I wrote about how you could use a couple of fields in the $ndo$dbproperty table to create a ConvertInvalidChars() function that would turn your NAV company name into the prefix for the table name as it is used in the SQL database. This week we’re going to write some SQL that will create a dynamic select statement that we can use to create our view.&lt;/p&gt;  &lt;h2&gt;What is Dynamic SQL?&lt;/h2&gt;  &lt;p&gt;Dynamic SQL is when we use programming code to build up our SQL Select statement in a text variable and then execute that statement. In the case of our all company view, we don’t know how many companies we have or what they’re called, so we’re going to need to write something that will read the companies in the database and generate the correct SQL statement for us.&lt;/p&gt;  &lt;p&gt;Here a simple example that shows that you can build up your SQL statement as a string and then use the EXEC() command to execute it.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(4000)     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; = &lt;span style="color:red;"&gt;&amp;#39;SELECT Name FROM Company&amp;#39;&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;EXEC&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;)     &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;The results of running this SQL is exactly the same as typing SELECT Name FROM Company into a query window and pressing F5.&lt;/p&gt;  &lt;h2&gt;Going Loopy with Cursors&lt;/h2&gt;  &lt;p&gt;Now we need to build up our SQL statement by looping through each of the companies in the database. To do this we’re going to use a cursor. A cursor is good because it allows you to fetch data back from the database one row at a time and then do something with the results. The downside to cursors is that they are slow (and this is one of the reasons that the performance of NAV is not as good as it could be as it makes extensive use of cursors when fetching data from the server).&lt;/p&gt;  &lt;p&gt;In addition to using a cursor, we’re going to use the UNION ALL statement that will join the results from our select statements together into a single dataset – this is useful since we are trying to create a combined view, which means we need a single result set. Here’s the code:&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(30)     &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(4000) = &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;     &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;CURSOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Company;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;OPEN&lt;/span&gt; mycur     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;@@FETCH_STATUS&lt;/span&gt; = 0     &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; &amp;lt;&amp;gt; &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;UNION ALL &amp;#39;&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;SELECT [Company Name] = &amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt; + &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt; + &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;, * FROM [&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;) + &lt;span style="color:red;"&gt;&amp;#39;$Vendor] &amp;#39;&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;     &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:#008000;"&gt;--EXEC(@SQLCommand)&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;PRINT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;CLOSE&lt;/span&gt; mycur     &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DEALLOCATE&lt;/span&gt; mycur     &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;As you can see I’ve commented out my EXEC command and replaced it with a PRINT command so we can see the SQL that gets generated in the message window. Here’s the SQL code it generates (obviously it doesn’t generate all of the formatting, I just inserted that to make it easier to follow the code):&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Company Name] = &lt;span style="color:red;"&gt;&amp;#39;CRONUS Australia Pty. Ltd.&amp;#39;&lt;/span&gt;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [CRONUS Australia Pty_ Ltd_$Vendor]     &lt;br /&gt;&lt;span style="color:blue;"&gt;UNION&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;ALL&lt;/span&gt;     &lt;br /&gt;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [Company Name] = &lt;span style="color:red;"&gt;&amp;#39;CRONUS New Zealand Ltd.&amp;#39;&lt;/span&gt;,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; *     &lt;br /&gt;&lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [CRONUS New Zealand Ltd_$Vendor]     &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;If you copied that SQL statement into a query window, you’d see a dataset that contains all of the fields from our Vendor table for each of the companies with a new first column called “Company Name”. Obviously you’d need to change this if you had an actual field called “Company Name” in your table. &lt;/p&gt;  &lt;h2&gt;Making the View&lt;/h2&gt;  &lt;p&gt;The only thing left to do now is put in the CREATE VIEW AS code to create our view. I’m going to call my view Company Vendor. Here’s the final SQL that will create my view.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(30)    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(4000) = &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;CURSOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FOR&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Company;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;OPEN&lt;/span&gt; mycur    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#ff00dc;"&gt;@@FETCH_STATUS&lt;/span&gt; = 0    &lt;br /&gt;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; &amp;lt;&amp;gt; &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;UNION ALL &amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;ELSE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;CREATE VIEW [Company Vendor] AS &amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt; += &lt;span style="color:red;"&gt;&amp;#39;SELECT [Company Name] = &amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt; + &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt; + &lt;span style="color:red;"&gt;&amp;#39;&amp;#39;&lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;, * FROM [&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( &lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;) + &lt;span style="color:red;"&gt;&amp;#39;$Vendor] &amp;#39;&lt;/span&gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FETCH&lt;/span&gt; mycur &lt;span style="color:blue;"&gt;INTO&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@CompanyName&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;EXEC&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;)    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;PRINT&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@SQLCommand&lt;/span&gt;    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;CLOSE&lt;/span&gt; mycur    &lt;br /&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;DEALLOCATE&lt;/span&gt; mycur    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;Next week we&amp;#39;ll look at the final steps of making this view available as a linked table in NAV and talk about some of the potential gotcha’s.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=443" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/SQL/default.aspx">SQL</category></item><item><title>Creating a view across all companies–part 1</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/08/15/creating-a-view-across-all-companies-part-1.aspx</link><pubDate>Sun, 15 Aug 2010 00:31:11 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:442</guid><dc:creator>David Roys</dc:creator><slash:comments>2</slash:comments><description>&lt;h2&gt;The Linked Table&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_47D3F8C2.png"&gt;&lt;img style="border-right-width:0px;margin:0px 10px 10px 0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" class="wlDisabledImage" title="image" border="0" alt="image" align="left" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_127AC090.png" width="125" height="123" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Have you ever wanted to search across multiple companies in a NAV database simultaneously? It&amp;#39;s really not that difficult as long as you&amp;#39;re using a SQL database. In this series of blog posts, I&amp;#39;ll give you a step by step guide on how to create a combined vendor list. This principal can be applied to any of the tables in NAV. First of all, we need to cover some basics.&lt;/p&gt;  &lt;p&gt;NAV has the facility to create a table definition that is linked to a view in the database that has the same name as the table. This can be a useful way to directly access data from other systems from within NAV, but it can also be useful for aggregating data that already exists in the NAV database. This could be combining data from multiple companies into a single view, as in this example, or could be combining G/L Entries and Dimensions into a single screen with the ability to search and filter on the dimensions. You could even use this technique to speed up slow processes by using SQL&amp;#39;s powerful set-based queries to replace a lot of effort needed by NAV&amp;#39;s much slower cursor-based operations.&lt;/p&gt;  &lt;p&gt;   &lt;br /&gt;To follow this example you&amp;#39;ll need a sample NAV database that you can play in without breaking anything and access to SQL Management Studio.&lt;/p&gt;  &lt;h2&gt;Getting Rid of Invalid Characters&lt;/h2&gt;  &lt;p&gt;If you’ve ever looked at the table names in a SQL database for Dynamics NAV, you’ll have noticed that the table names have the company name at the start and that certain characters have been replaced. In the demo database for New Zealand, we have two companies: CRONUS Australia Pty. Ltd. and CRONUS New Zealand Ltd. If I look for the Vendor table in SQL I’ll see the following two table names:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;CRONUS Australia Pty_ Ltd_$Vendor &lt;/li&gt;    &lt;li&gt;CRONUS New Zealand Ltd_$Vendor&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;As you can see it’s basically the company name with a dollar sign followed by the table name, but some characters have been replaced. This is because when NAV creates the underlying SQL tables, it replaces some “invalid characters”. It does the same for the field names too.&lt;/p&gt;  &lt;p&gt;In this first part of our series on creating a view across all companies, we’ll create a function that will help us find the correct company name as used as the prefix for NAV tables.&lt;/p&gt;  &lt;p&gt;The characters that get replaced are stored in a field called invalididentifierchars in a system table [$ndo$dbproperty] (the square brackets aren’t actually part of the table name, they just make tell SQL to ignore funny characters like the dollar sign and any spaces that may be part of the table name). There’s another useful field in the [$ndo$dbproperty] table that we’ll need for this exercise called convertidentifiers. This tells the system whether we want to bother converting identifiers or not. You can change both of these fields by going to the Classic Client for SQL and selecting &lt;strong&gt;Database &amp;gt; Alter&lt;/strong&gt; from the &lt;strong&gt;File&lt;/strong&gt; menu. Click on the Integration tab and you’ll see the options.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_0363E1B6.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" class="wlDisabledImage" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_7761F181.png" width="644" height="274" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We need to check to see if the Convert identifiers flag is set and, if it is, remove each of the characters from our company name and replace with an underscore.&lt;/p&gt;  &lt;p&gt;I’m going to create a SQL Function called ConvertInvalidChars that will do this for me. Here’s the SQL code. You should execute this in the NAV database.&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;IF&lt;/span&gt; OBJECT_ID( &lt;span style="color:red;"&gt;N&amp;#39;dbo.ConvertInvalidChars&amp;#39;&lt;/span&gt;,&lt;span style="color:red;"&gt;N&amp;#39;FN&amp;#39;&lt;/span&gt;) &lt;span style="color:gray;"&gt;IS&lt;/span&gt;&amp;#160;&lt;span style="color:gray;"&gt;NOT&lt;/span&gt;&amp;#160;&lt;span style="color:#a9a9a9;"&gt;NULL&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;DROP&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FUNCTION&lt;/span&gt; dbo.ConvertInvalidChars;     &lt;br /&gt;GO     &lt;br /&gt;&lt;span style="color:blue;"&gt;CREATE&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;FUNCTION&lt;/span&gt; dbo.ConvertInvalidChars     &lt;br /&gt;(&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(250)     &lt;br /&gt;)     &lt;br /&gt;RETURNS     &lt;br /&gt;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(250)     &lt;br /&gt;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160; &lt;br /&gt;&amp;#160;&lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;VARCHAR&lt;/span&gt;(128)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt; INTEGER     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;DECLARE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@ConvertIdentifiers&lt;/span&gt;&amp;#160;&lt;span style="color:blue;"&gt;AS&lt;/span&gt; INTEGER     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#8b0000;"&gt;@ConvertIdentifiers&lt;/span&gt; = convertidentifiers,     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt; = invalididentifierchars     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [$ndo$dbproperty]     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;IF&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@ConvertIdentifiers&lt;/span&gt; &amp;lt;&amp;gt; 1 &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; = 1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;WHILE&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; &amp;lt;= &lt;span style="color:#ff00dc;"&gt;LEN&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;BEGIN&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt; = &lt;span style="color:#ff00dc;"&gt;REPLACE&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;,&lt;span style="color:#ff00dc;"&gt;SUBSTRING&lt;/span&gt;( &lt;span style="color:#8b0000;"&gt;@InvalidIdentifierChars&lt;/span&gt;,&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt;,1),&lt;span style="color:red;"&gt;&amp;#39;_&amp;#39;&lt;/span&gt;)     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;SET&lt;/span&gt;&amp;#160;&lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; = &lt;span style="color:#8b0000;"&gt;@X&lt;/span&gt; + 1     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:blue;"&gt;RETURN&lt;/span&gt;(&lt;span style="color:#8b0000;"&gt;@p_StringToConvert&lt;/span&gt;)     &lt;br /&gt;&lt;span style="color:blue;"&gt;END&lt;/span&gt;     &lt;br /&gt;GO     &lt;br /&gt;    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;  &lt;h2&gt;&lt;font face="Calibri"&gt;Testing our Function&lt;/font&gt;&lt;/h2&gt;  &lt;p&gt;&lt;font face="Calibri"&gt;That previous bit of SQL will give us a SQL function that we can use in our code later on. Here’s an example of a select statement that uses the function.&lt;/font&gt;&lt;/p&gt; &lt;code style="font-size:12px;"&gt;&lt;span style="color:blue;"&gt;SELECT&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Name,    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [No Invalid Chars Name] = dbo.ConvertInvalidChars( Name),    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [NAV Vendor &lt;span style="color:blue;"&gt;Table&lt;/span&gt; Name] = &lt;span style="color:red;"&gt;&amp;#39;[&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( Name) + &lt;span style="color:red;"&gt;&amp;#39;$&amp;#39;&lt;/span&gt; + dbo.ConvertInvalidChars( &lt;span style="color:red;"&gt;&amp;#39;Vendor&amp;#39;&lt;/span&gt;) + &lt;span style="color:red;"&gt;&amp;#39;]&amp;#39;&lt;/span&gt;    &lt;br /&gt;&lt;span style="color:blue;"&gt;FROM&lt;/span&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Company    &lt;br /&gt;&lt;/code&gt;  &lt;p&gt;&lt;font face="Calibri"&gt;and here’s the output from that select statement.&lt;/font&gt;&lt;/p&gt;  &lt;table border="0" cellspacing="0" cellpadding="2" width="683"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="192"&gt;&lt;strong&gt;Name&amp;#160;&amp;#160;&amp;#160; &lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="195"&gt;&lt;strong&gt;No Invalid Chars Name&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="294"&gt;&lt;strong&gt;NAV Vendor Table Name&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="192"&gt;CRONUS Australia Pty. Ltd.&lt;/td&gt;        &lt;td valign="top" width="195"&gt;CRONUS Australia Pty_ Ltd_&lt;/td&gt;        &lt;td valign="top" width="294"&gt;[CRONUS Australia Pty_ Ltd_$Vendor]&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="192"&gt;CRONUS New Zealand Ltd.&lt;/td&gt;        &lt;td valign="top" width="195"&gt;CRONUS New Zealand Ltd_&lt;/td&gt;        &lt;td valign="top" width="294"&gt;[CRONUS New Zealand Ltd_$Vendor]&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&lt;code&gt;&lt;font face="Calibri"&gt;Hopefully you can see where I’m going with this. Next week, I’ll show you how we are going to use this function to build a SQL View for combining multiple company tables together.&lt;/font&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=442" width="1" height="1"&gt;</description></item><item><title>You Could Win Visual Studio 2010 Ultimate + MSDN</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/07/25/you-could-win-visual-studio-2010-ultimate-msdn.aspx</link><pubDate>Sun, 25 Jul 2010 00:02:17 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:440</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;img src="http://www.microsoft.com/visualstudio/_base_v1/images/boxshots/hero_single_ultimate_boxshot.png" alt="" /&gt;&lt;/p&gt;  &lt;p&gt;In order to drive awareness of the recent launch of Visual Studio 2010, Microsoft has given me &lt;font size="4"&gt;&lt;strong&gt;2&lt;/strong&gt;&lt;/font&gt; x Not for Resale (NFR) &lt;strong&gt;&lt;font size="3"&gt;Visual Studio 2010 Ultimate with MSDN subscription cards to give away&lt;/font&gt;&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Take a look on the &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/2010-editions/ultimate" target="_blank"&gt;Visual Studio Product Site&lt;/a&gt; and you’ll see that to buy one of these subscriptions will set you back a lot of money—but I’m giving them away for free!&lt;/p&gt;  &lt;h3&gt;What do you need to do?&lt;/h3&gt;  &lt;p&gt;As you know, Microsoft Dynamics NAV 2009 SP1 introduced a new feature called Control Add-ins. These are .NET controls that let you do all kinds of stuff like display customer locations using Bing Maps, display Visio diagrams, capture signatures, display charts, have spell checking, edit HTML…all within the RoleTailored client. What a lot of stuff! The thing is, you’re only really limited by your imagination – these are just some examples of controls that have already been created. What control would you create?&lt;/p&gt;  &lt;p&gt;I’m not asking you to build one of these controls to win the prize, I just want you to &lt;strong&gt;&lt;font size="4"&gt;think of an idea for a control add-in and write about it&lt;/font&gt;&lt;/strong&gt;. Write a Word document describing your concept and include pictures (mock-ups or sketches) of how you see it working. You can use any version of Word for your submission, but don’t use other formats because if I can’t read it, you can’t win. Also all submissions must be in English and if you write in Text Speak or some strange form of English that I can’t understand, you’re chances of winning are slim. You’re submission should be around two pages in Word with a picture or two.&lt;/p&gt;  &lt;h3&gt;How do you submit your entry?&lt;/h3&gt;  &lt;p&gt;The purpose of this competition is to get people thinking about custom controls for NAV 2009 SP1 and sharing their ideas. I have created a Forum for you to upload your ideas so they are then shared with everyone. Write a forum post giving a brief outline of your idea and you should be able to attach a Word document to the forum post. The &lt;a href="http://www.teachmenav.com/forums/22.aspx" target="_blank"&gt;Control Add-ins Forum&lt;/a&gt; is here. You need to be registered on TeachMeNAV to be able to make posts. I will need to send an e-mail to you about the prize if you win, so make sure you use a real e-mail address when you register. I’ll put in a sample posting so you know what I’m looking for. I’ll be searching for your idea online so don’t bother just posting someone else’s idea or blog post.&lt;/p&gt;  &lt;h3&gt;Closing Date and Terms and Conditions&lt;/h3&gt;  &lt;ol&gt;   &lt;li&gt;I’ll leave the forum open until the end of August 2010. You must make your submission before then to be in to win.&lt;/li&gt;    &lt;li&gt;Only submissions made through the &lt;a href="http://www.teachmenav.com/forums/22.aspx" target="_blank"&gt;Control Add-ins Forum&lt;/a&gt; will be considered.&lt;/li&gt;    &lt;li&gt;I am going to pick the winners and my decision is final.&lt;/li&gt;    &lt;li&gt;The Visual Studio 2010 MSDN subscription cards are the only prizes. There is no cash alternative and if for any reason your subscription card does not work, you’ll need to sort this out with Microsoft and not with me.&lt;/li&gt;    &lt;li&gt;I’ll announce the winning entries before the end of September 2010.&lt;/li&gt;    &lt;li&gt;The competition is not open to Dynamics NAV MVPs (sorry guys but you already have an MSDN subscription, so let’s give someone else a chance).&lt;/li&gt;    &lt;li&gt;By submitting your ideas, they are shared with the world. If someone decides to build your idea, good luck to them.&lt;/li&gt; &lt;/ol&gt;  &lt;h3&gt;What’s the catch?&lt;/h3&gt;  &lt;p&gt;There’s no catch, but there are some conditions and limitations surrounding the prize.&lt;/p&gt;  &lt;p&gt;The 12-month MSDN subscription has some restrictions with it being a NFR version (technical support benefits and MSDN Magazine are not included, and all software benefits, including Microsoft Office 2010 products, are for development and test purposes only).&lt;/p&gt;  &lt;p&gt;The subscriptions need to be registered within 180 days of when &lt;em&gt;I&lt;/em&gt; received them (that means you have until around the end of December 2010 to register, but I won’t be responsible for you neglecting to register—if you win a prize, register it straight away).&lt;/p&gt;  &lt;h3&gt;Resources&lt;/h3&gt;  &lt;p&gt;The official Microsoft documentation about add-ins online at &lt;a href="http://msdn.microsoft.com/en-us/library/dd983700.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd983700.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Freddy Kristiansen’s Blog &lt;a href="http://blogs.msdn.com/b/freddyk/archive/2009/06/07/integration-to-virtual-earth-part-4-of-4.aspx"&gt;http://blogs.msdn.com/b/freddyk/archive/2009/06/07/integration-to-virtual-earth-part-4-of-4.aspx&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Christian Abeln’s blog on Add-ins &lt;a href="http://blogs.msdn.com/b/cabeln/archive/2009/05/06/add-ins-for-the-roletailored-client-of-microsoft-dynamicsnav-2009-sp1-part1.aspx"&gt;http://blogs.msdn.com/b/cabeln/archive/2009/05/06/add-ins-for-the-roletailored-client-of-microsoft-dynamicsnav-2009-sp1-part1.aspx&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=440" width="1" height="1"&gt;</description></item><item><title>Action Images</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/06/22/action-images.aspx</link><pubDate>Tue, 22 Jun 2010 10:55:00 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:439</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;When you want to attach an image to an Action in NAV 2009, you need to pick from one of the standard images and use it to set the Image property. There&amp;rsquo;s a library with all of the 2009 and 2009 SP1 images on MSDN (&lt;a href="http://msdn.microsoft.com/en-us/library/dd568728.aspx" title="http://msdn.microsoft.com/en-us/library/dd568728.aspx"&gt;http://msdn.microsoft.com/en-us/library/dd568728.aspx&lt;/a&gt;). If you don&amp;rsquo;t know about Action Images, take a look at &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/library/dd568735.aspx"&gt;How to: Set an Image on an Action&lt;/a&gt; on MSDN.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a saying that necessity is the mother of invention, and for me that is certainly true. I needed to find an image to use on a new action and it took quite a while to scroll through the list of 310 images, trying to find one that looked vaguely like the action I had created.&lt;/p&gt;
&lt;p&gt;I figured it would be good if instead of scrolling through the entire list, I could search in a document of some kind. I started by cutting out each of the images from the MSDN library image and saving as an individual file with a name of the action image property value.&lt;/p&gt;
&lt;p&gt;Next I loaded these into an &lt;a target="_blank" href="http://teachmenav.com/media/g/actions/default.aspx?Sort=Subject&amp;amp;PageIndex=1"&gt;Action Images Media Gallery&lt;/a&gt; on this site and attached meta-data tags that would make it easier to search. Below is a screen shot of the Tag Cloud for all 310 images.&lt;/p&gt;
&lt;p&gt;&lt;a target="_blank" href="http://www.teachmenav.com/media/default.aspx?Sort=Subject&amp;amp;PageIndex=1"&gt;&lt;img height="223" width="644" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_3A80968D.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s an example of how it works. Let&amp;rsquo;s say I&amp;rsquo;ve created an action for adding reminders. I can look through the tags and see there&amp;rsquo;s an Alarm Bell tag. I click that and see the following images.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_2F938F78.png"&gt;&lt;img height="237" width="644" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_78D63473.png" alt="image" border="0" title="image" style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So there are 5 to choose from. I think I&amp;rsquo;d pick the &amp;ldquo;CreateReminders&amp;rdquo; that has the alarm and the sparkle.&amp;nbsp;The Tag Cloud in the side bar shows all tags, but I&amp;#39;m struggling to get the view more link at the bottom of the cloud to show all of the tags.&lt;/p&gt;
&lt;p&gt;This took a ridiculous amount of time to complete. I hope you find it as useful as I do. Oh and the link to the gallery? Here it is &lt;a href="http://www.teachmenav.com/media/default.aspx?Sort=Subject&amp;amp;PageIndex=1"&gt;Action Image Tag Cloud&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=439" width="1" height="1"&gt;</description></item><item><title>Microsoft Dynamics NAV 2009 Application Design</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/06/01/microsoft-dynamics-nav-2009-application-design.aspx</link><pubDate>Tue, 01 Jun 2010 10:10:00 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:128</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;div class="book-image"&gt;&lt;img height="152" width="125" src="https://www.packtpub.com/sites/default/files/imagecache/productview/0967EN_MockupCover.jpg" alt="Microsoft Dynamics NAV 2009 Application Design" title="Microsoft Dynamics NAV 2009 Application Design" class="imagecache imagecache-productview" /&gt;&lt;/div&gt;
&lt;div class="book-image"&gt;I found out today that Mark Brummel (Dynamics NAV MVP and blogger) has written a book on Dynamics NAV 2009. You can read about it on &lt;a href="http://dynamicsuser.net/blogs/mark_brummel/archive/2010/06/01/new-nav-book-microsoft-dynamics-nav-2009-application-design.aspx"&gt;his blog post here&lt;/a&gt;, and you can pre-order from &lt;a href="https://www.packtpub.com/microsoft-dynamics-nav-2009-application-design/book"&gt;the PACKT web site&lt;/a&gt;.&lt;/div&gt;
&lt;div class="book-image"&gt;&lt;/div&gt;
&lt;div class="book-image"&gt;The one thing I did notice was that the PACKT web site has undergone a significant redesign and looks really sharp. You should go an take a look.&lt;/div&gt;
&lt;div class="book-image"&gt;&lt;/div&gt;
&lt;div class="book-image"&gt;Here is some blurb from the PACKT site.&lt;/div&gt;
&lt;div class="book-image"&gt;&lt;/div&gt;
&lt;div class="book-image"&gt;&lt;strong&gt;What you will learn from this book :&lt;br /&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;Implement Microsoft Dynamics NAV ERP suite with a sample industry application throughout the book&lt;/li&gt;
&lt;li&gt;Set up Dynamics NAV and customize it for various industries including fashion, retail, and the automobile industry&lt;/li&gt;
&lt;li&gt;Get to grips with key Dynamics NAV features such as Inventory Valuation, Item Tracking, and Reservations&lt;/li&gt;
&lt;li&gt;Learn about B2B and B2C Interfacing and the fundamentals of Application Design&lt;/li&gt;
&lt;li&gt;Learn and customize application features designed by Microsoft such as Financial Management, CRM, Manufacturing, Distribution / Wholesale, and Retail and extend them safely&lt;/li&gt;
&lt;li&gt;Design your applications to have a good balance between cost of ownership and functionality&lt;/li&gt;
&lt;li&gt;Analyze operation data based on sales demographics using Dynamics NAV CRM&lt;/li&gt;
&lt;li&gt;Extend your core applications using interfaces such as Flatfile, CSV, XMLports, ADO, EDI standards, and web services&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Approach&lt;/b&gt;&lt;br /&gt;
&lt;p&gt;This book is a tutorial in an easy-to-read style. It will show Dynamics NAV developers how to create applications of different kinds with sufficient examples throughout.&lt;/p&gt;
&lt;b&gt;Who this book is written for&lt;/b&gt;&lt;br /&gt;
&lt;p&gt;If you are a NAV consultant and developer, or designer of business applications you will benefit most from this book.&lt;/p&gt;
&lt;p&gt;The book assumes that you have a basic understanding of business management systems and application development, with a working knowledge of Microsoft Dynamics NAV.&amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;div class="book-image"&gt;Well done to Mark for such a huge effort. I look forward to reading it.&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=128" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Book+News/default.aspx">Book News</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Writing/default.aspx">Writing</category></item><item><title>Dropbox Rocks</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/04/05/dropbox-rocks.aspx</link><pubDate>Sun, 04 Apr 2010 20:21:46 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:119</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I’ve been using Dropbox to help with my writing. It’s a great tool and I think anyone that’s writing for a hobby should have it in their kitbag.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_4C1C221C.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="image" border="0" alt="image" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_5528AD9D.png" width="260" height="193" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;They sent me a link that helps people sign up that will give me more storage if you follow it (that’s what the referrals part at the end of the link is all about). It’s totally free and you get 2GB storage and backups for no charge. You can of course pay for more storage if you need it. Here’s the link…&lt;/p&gt;  &lt;p&gt;&lt;a title="https://www.dropbox.com/referrals/NTQ5NjE3MDc5" href="https://www.dropbox.com/referrals/NTQ5NjE3MDc5"&gt;https://www.dropbox.com/referrals/NTQ5NjE3MDc5&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;So what is Dropbox anyway?&lt;/p&gt;  &lt;p&gt;It’s an online storage area that means you can easily access your writing from any computer.&lt;/p&gt;  &lt;p&gt;A program installed on my computer allows me to work with files in a folder (nothing special, you just nominate which folder will be your Dropbox folder) then whenever you save to this folder or drag files into it, the file gets uploaded to the Cloud storage in the background. It’s that easy!&lt;/p&gt;  &lt;p&gt;You can have Dropbox installed on many computers accessing the same account or you can access the files through the Web interface. I have it installed on my home and work computer and on my iPhone, which means that I can work on the same documents on any of these devices and don’t need to worry about keeping different versions in sync.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=119" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Writing/default.aspx">Writing</category></item><item><title>About This Report – No need to run reports twice</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/03/14/about-this-report-no-need-to-run-reports-twice.aspx</link><pubDate>Sun, 14 Mar 2010 03:18:42 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:118</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;&lt;a href="http://www.teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_02A70875.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="image" border="0" alt="image" src="http://www.teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/image_5F00_thumb_5F00_6649A087.png" width="640" height="340" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It&amp;#39;s been a while since I last made a post and there are a few reasons. Bejweled Blitz on the iPhone is a big part, but also, it seems that there has been a real period of consolidation for me just recently: taking a lot of the things I learnt and applying them on projects, so not a lot of new stuff to share, just lots of time-consuming work. That&amp;#39;s the excuses for not blogging out of the way, now on with the post.&lt;/p&gt;  &lt;p&gt;I came across a top tip yesterday courtesy of a work colleague and felt it was simply too good not to share. If you do any report development in NAV 2009, keep reading.&lt;/p&gt;  &lt;p&gt;One of the mysteries of working reports in NAV 2009 is understanding what is in the dataset when the reporting services client renders the report. In NAV 2009 we had the undocumented Ctrl+Shift+Alt+F12 key press which you could use when previewing the report. This key press opens a window with a list containing the entire dataset, allowing you to copy and paste into Excel. This is great for figuring out how you should be sorting and grouping your dataset for the required results.&lt;/p&gt;  &lt;p&gt;Then when SP1 for NAV 2009 came out we got the Ctrl+Alt+F1 (About This Report) key press that could be used to do the same, but for reasons that I can only assume are related to the way data is paged on the client, the first time you select the option after previewing the report you get told you need to run the report again and select the About This Report option again. This need to repeat your actions in order to get your goal is mildly annoying. This is where the top tip comes in. When your options page for the report is displayed, select Ctrl+Alt+F1, About This Page. Now when you preview the report you can press Ctrl+Alt+F1 and see the full dataset and you don’t need to run the report again. It&amp;#39;s not perfect but better than having to run the report twice.&lt;/p&gt;  &lt;p&gt;So what would be a better way of doing this? I would suggest a setting in the config file that says keep dataset for reports. This way, developers could have this setting on and end users could leave it switched off.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=118" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Tip/default.aspx">Tip</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Reporting/default.aspx">Reporting</category></item><item><title>NAV 2009 Server Starts and then Stops</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/01/20/nav-2009-server-starts-and-then-stops.aspx</link><pubDate>Wed, 20 Jan 2010 00:31:38 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:116</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;Have you ever tried to create a NAV 2009 Server service that runs under a domain account and when you try to start it, the service starts and them immediately stops again.&lt;/p&gt;  &lt;p&gt;Then, if you look in the Windows Event Log for the error message you see something like this…&lt;/p&gt;  &lt;p&gt;&lt;em&gt;The service MicrosoftDynamicsNavServer$DynamicsNAV failed to start. This could be caused by a configuration error. Detailed error information:System.ServiceModel.CommunicationException: The service endpoint failed to listen on the URI &amp;#39;net.tcp://vm-dev-100118.rad.intergen.org.nz:7046/DynamicsNAV/Service&amp;#39; because access was denied.&amp;#160; Verify that the current user is granted access in the appropriate allowedAccounts section of SMSvcHost.exe.config. ---&amp;gt; System.ComponentModel.Win32Exception: Access is denied&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;I’ve had this a few times and my sledgehammer solution has been to make the domain account that is running the service a member of the local machine Administrators group. OK, I realise this is overkill but it works.&lt;/p&gt;  &lt;p&gt;Today I finally took the time to figure out the correct way of granting the permissions to the domain account to allow it to listen on the specified port.&lt;/p&gt;  &lt;p&gt;First of all we need to know the SID for the domain account. There may be other ways to find this out, but here is a suggestion that works:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Start a command prompt running under the context of the user you want to know the SID for by typing runas /user:domain\nav2009nstuser cmd.exe in a command prompt where domain is your domain and nav2009nstuser is the account that is running the NAV Server Tier. &lt;/li&gt;    &lt;li&gt;The system will prompt for the nav2009nstuser password. &lt;/li&gt;    &lt;li&gt;A new command prompt opens and you will notice in the title of the window it says cmd.exe (running as domain\nav2009nstuser). &lt;/li&gt;    &lt;li&gt;In this new command window type whoami /user &lt;/li&gt;    &lt;li&gt;You will see the SID of the user account. Copy this as you will need it in the next step. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;These instructions are meant to work on Windows 7, so apologies if some of these things don’t work for you.&lt;/p&gt;  &lt;p&gt;Now you need to edit the C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\SMSvcHost.exe.config file or the C:\Windows\Microsoft.NET\Framework64\v3.0\Windows Communication Foundation\SMSvcHost.exe.config file.&lt;/p&gt;  &lt;p&gt;The file includes a &amp;lt;runtime&amp;gt; element and beneath that a commented out section that shows what to include for the net.tcp permissions we want to add. Insert the following section below the &amp;lt;/runtime&amp;gt; closing tag and before the start of the comment as so that part of the file looks like this…&lt;/p&gt;  &lt;p&gt;&amp;lt;/runtime&amp;gt;   &lt;br /&gt;&amp;lt;system.serviceModel.activation&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;net.tcp listenBacklog=&amp;quot;10&amp;quot; maxPendingConnections=&amp;quot;100&amp;quot; maxPendingAccepts=&amp;quot;2&amp;quot; receiveTimeout=&amp;quot;00:00:10&amp;quot; teredoEnabled=&amp;quot;false&amp;quot;&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;allowAccounts&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;add securityIdentifier=&amp;quot;S-1-1-1 this is your SID&amp;quot;/&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/allowAccounts&amp;gt;    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/net.tcp&amp;gt;    &lt;br /&gt;&amp;lt;/system.serviceModel.activation&amp;gt;    &lt;br /&gt;&amp;lt;!-- Below are some sample config settings:&amp;#160;&amp;#160;&amp;#160; &lt;/p&gt;  &lt;p&gt;replacing S-1-1-1 this is your SID with the correct SID you found in the previous step.&lt;/p&gt;  &lt;p&gt;Now reboot the machine (restarting the service is not enough).&lt;/p&gt;  &lt;p&gt;Your service should now start correctly. Thanks to Dominick Baier who posted on &lt;a title="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/b1cc46af-a70d-4793-b5fe-b61450ef5387" href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/b1cc46af-a70d-4793-b5fe-b61450ef5387"&gt;http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/b1cc46af-a70d-4793-b5fe-b61450ef5387&lt;/a&gt; which gave me the info I needed to get this working.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=116" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category></item><item><title>The specified path is invalid. When using UPLOADINTOSTREAM.</title><link>http://www.teachmenav.com/blogs/dave/archive/2010/01/01/the-specified-path-is-invalid-when-using-uploadintostream.aspx</link><pubDate>Fri, 01 Jan 2010 02:16:21 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:113</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I recently tried using UPLOADINTOSTREAM to load a file from the RoleTailored client into a temporary file on the NAV Server so that I could then process it. This is needed in NAV 2009 because it has three tiers and the tier on which the code executes does not necessarily have access to the files that are accessible on the client. Think about it, you’re c: drive is not the same place as the c: drive on the server.&lt;/p&gt;  &lt;p&gt;I tried using the F5 C/AL Symbol Menu to paste the function call with its arguments because, to be frank, I can never remember stuff like this. This pasted the following line of code:&lt;/p&gt;  &lt;p&gt;[Ok :=] UPLOADINTOSTREAM(DialogTitle, FromFolder, FromFilter, FromFile, NVInStream)&lt;/p&gt;  &lt;p&gt;I then replaced the parameters with the appropriate text strings and variables which gave me this:&lt;/p&gt;  &lt;p&gt;UPLOADINTOSTREAM(&amp;#39;Profile Metadata&amp;#39;, &amp;#39;&amp;#39;, &amp;#39;*.XML&amp;#39;, FileName, InStream);&lt;/p&gt;  &lt;p&gt;FileName and InStream variables of type Text 1024 and InStream respectively.&lt;/p&gt;  &lt;p&gt;When I tried to run this command I kept getting this error message:&lt;/p&gt;  &lt;p align="center"&gt;&lt;font size="2" face="Courier New"&gt;Microsoft Dynamics NAV      &lt;br /&gt;--------------------------- &lt;/font&gt;&lt;/p&gt;  &lt;p align="center"&gt;&lt;font size="2" face="Courier New"&gt;The specified path is invalid.      &lt;br /&gt;---------------------------       &lt;br /&gt;OK       &lt;br /&gt;---------------------------&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;I couldn’t figure out why I was getting this error, but it turns out using an incorrect value in the FromFilter was causing the problem.&lt;/p&gt;  &lt;p&gt;When I changed my line of code to be more like the example in the online help it all worked fine:&lt;/p&gt;  &lt;p&gt;UPLOADINTOSTREAM(&amp;#39;Profile Metadata&amp;#39;, &amp;#39;&amp;#39;, &amp;#39;XML File *.XML| *.XML&amp;#39;, FileName, InStream);&lt;/p&gt;  &lt;p&gt;I searched for the error message and UPLOADINTOSTREAM in order to find the answer, but found nothing, hence the reason for this blog post.&lt;/p&gt;  &lt;p&gt;Oh, and Happy New Year!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=113" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009/default.aspx">NAV 2009</category></item><item><title>Book Review: Programming Microsoft Dynamics NAV 2009</title><link>http://www.teachmenav.com/blogs/dave/archive/2009/12/21/book-review-programming-microsoft-dynamics-nav-2009.aspx</link><pubDate>Sun, 20 Dec 2009 22:53:45 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:111</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;table border="0" cellspacing="0" cellpadding="2" width="583"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&lt;img src="https://www.packtpub.com/images/full/1847196527.jpg" width="194" height="240" alt="" /&gt;&lt;/td&gt;        &lt;td valign="top" width="381"&gt;&lt;strong&gt;Author:&lt;/strong&gt; David Studebaker          &lt;br /&gt;          &lt;br /&gt;&lt;strong&gt;Publisher:&lt;/strong&gt; PACKT          &lt;br /&gt;          &lt;br /&gt;          &lt;p&gt;&lt;strong&gt;ISBN:&lt;/strong&gt; 978-1-847196-52-1            &lt;br /&gt;            &lt;br /&gt;&lt;strong&gt;Published:&lt;/strong&gt; November 2009&lt;/p&gt;       &lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Available from &lt;a title="the PACKT web site" href="http://www.packtpub.com/programming-microsoft-dynamics-nav-2009/mid/2907099ks64d?utm_source=teachmenav.com&amp;amp;utm_medium=affiliate&amp;amp;utm_content=blog&amp;amp;utm_campaign=mdb_000066"&gt;the PACKT web site&lt;/a&gt; and &lt;a title="Amazon.com" href="http://www.amazon.com/gp/product/1847196527?ie=UTF8&amp;amp;tag=gassbradum-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=390957&amp;amp;creativeASIN=1847196527"&gt;Amazon.com&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;When I saw that David Studebaker had written a new book on Programming Microsoft Dynamics NAV 2009, the first thing I wanted to know was whether this is a completely new book or a tarted-up version of his previous book &lt;a href="http://gaspodethewonderdog.blogspot.com/2007/12/book-review-programming-microsoft.html" target="_blank"&gt;which I reviewed in December 2007&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Now that I have finished reading it (and it’s a whopping 559 pages in 9 chapters) I can tell you that it’s a bit of both. There is a lot of new content in this book and the programming scenario that flows throughout the book has been completely redone and is, in my opinion, much improved. The whole book has a fresh new approach but I kept getting a sense of déjà lu. The ‘read it before’ feeling is not surprising: this is a re-write and if you open this book and the previous one side-by-side, you’ll see a lot of the content is fundamentally the same. That’s fair enough, there’s only so much you can write on the subject of programming NAV and the re-writing and corrections has improved the book greatly.&lt;/p&gt;  &lt;p&gt;Each chapter finishes with a pop quiz with a number of carefully considered questions to help you determine whether you have grasped the basic concepts. The book is much easier to read than the previous version, and there are considerably less mistakes (I still managed to find a few although the majority were proofing errors rather than programming errors).&lt;/p&gt;  &lt;p&gt;Sadly for me, the chapter on Forms has been re-written as a chapter on Pages which means this book is no longer a complete introduction to NAV programming and if you want to learn about creating Forms, we are told to buy the other book as well (or if you’re on a budget, you could consider reading the &lt;a href="http://www.packtpub.com/files/implementing-microsoft-dynamics-nav-2009-sample-chapter-6-modifying-the-system.pdf" target="_blank"&gt;sample chapter of my book&lt;/a&gt; instead). There is no mention of Form transformation, which for me is a large part of NAV 2009 development. At the moment, the easiest way to develop and maintain NAV 2009 is to create Forms and use the Form Transformation tool to create the pages. This book is not going to help you do that, although you will get a good understanding of what pages are and what you can do with them. If you want some help with the more complex areas, such as Page Transformation, advanced Report Transformation or Matrix Pages, you should consider &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2009/06/28/book-review-microsoft-dynamics-nav-2009-inside.aspx" target="_blank"&gt;Rene Gayer’s book&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;When I wrote my original review of Programming Microsoft Dynamics NAV two years ago, I said that this was the only book on programming NAV and that is reason enough to buy it. There are now two other books on NAV 2009, &lt;a href="http://www.teachmenav.com/blogs/dave/archive/2009/06/28/book-review-microsoft-dynamics-nav-2009-inside.aspx" target="_blank"&gt;Rene’s book&lt;/a&gt; and &lt;a href="http://www.packtpub.com/implementing-microsoft-dynamics-nav-2009/book/mid/190109h5mbvn" target="_blank"&gt;the one I co-authored with Vjeko&lt;/a&gt;. There is &lt;a href="http://msdn.microsoft.com/en-us/library/dd448639.aspx" target="_blank"&gt;Microsoft Dynamics NAV 2009 Developer and IT Pro Documentation&lt;/a&gt; available online at msdn and there are now some amazing blogs that cover advanced topics such as creating Web service-consuming applications and RTC Client Add-ins, so the question remains, should you buy this book?&lt;/p&gt;  &lt;p&gt;If you are new to programming NAV and have not read David’s previous book, then this is a great book for you and you will learn a lot from it. Definitely buy it.&lt;/p&gt;  &lt;p&gt;If you have read David’s previous book and are now looking for a guide to what’s new in NAV 2009 you should probably consider other sources that will give you the overview of what’s new with a lot more new content (such as my book, Rene’s book or the online articles and blogs).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h3&gt;Postscript for the E-book Enthusiasts&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/iPhoneReader_5F00_1EC73821.jpg"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:inline;border-top:0px;border-right:0px;" title="" border="0" alt="" src="http://teachmenav.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/dave/iPhoneReader_5F00_thumb_5F00_67317732.jpg" width="244" height="151" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As part of my review of this book, I wanted to try reading the e-book version so that I could compare that to the printed copy. Printed books still have a lot of advantages over e-books, although I think you should consider buying both if you can afford it. This gives you the ease and comfort of reading a paper book with the convenience of being able to search the contents for a specific topic. There are some good deals when buying both the e-book and the p-book from the Packt web site, although it’s a shame you don’t get the e-book for free when you buy the printed copy. I first tried reading the e-book using my Sony PRS-505 Reader &lt;a href="http://www.sony.co.uk/hub/reader-ebook"&gt;http://www.sony.co.uk/hub/reader-ebook&lt;/a&gt; . This uses electronic ink to display the text which provides a close-to-paper reading experience. The PDF document format is not ideally suited to the PRS-505. The large white space borders mean the text is tiny even if you read it in split-page landscape mode. You can reflow the text to increase the text size but this spoils the layout. The book is also so large that re-flowing it locked my reader for over 20 minutes. Next I tried using GoodReader (&lt;a href="http://www.goodreader.net/goodreader.html"&gt;http://www.goodreader.net/goodreader.html&lt;/a&gt;) on my Apple iPhone to read the book. This was great. GoodReader lets you zoom the display to get rid of the large borders and then lock the horizontal scroll making it easy to flick through the text. I actually read quite a bit of the book like this and I found the text clear and the images crisp. If you have an iPhone or iPod touch, you should seriously consider this as an option.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=111" width="1" height="1"&gt;</description></item><item><title>Sample Book Chapters</title><link>http://www.teachmenav.com/blogs/dave/archive/2009/11/27/sample-book-chapters.aspx</link><pubDate>Fri, 27 Nov 2009 05:31:00 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:104</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I wanted to find something from Chapter 7 of my book today and I realised that I hadn&amp;#39;t posted links to the sample chapters. There are two sample chapters available. Chapter 7 is presented in two articles on the PACKT article network and Chapter 6 is available as a PDF download directly from the PACKT web site and also from MIBUSO.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.packtpub.com/files/implementing-microsoft-dynamics-nav-2009-sample-chapter-6-modifying-the-system.pdf"&gt;Chapter 6: Modifying the System (PDF)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.packtpub.com/article/extending-application-using-microsoft-dynamics-nav-2009-part1"&gt;Chapter 7 Part 1: Extending the Application (part 1 as an online article)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.packtpub.com/article/extending-application-using-microsoft-dynamics-nav-2009-part2"&gt;Chapter 7 Part 2: Extending the Application (part 2 as an online article)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=104" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Sample+Chapters/default.aspx">Sample Chapters</category></item><item><title>Where did my xRec go?</title><link>http://www.teachmenav.com/blogs/dave/archive/2009/11/02/where-did-my-xrec-go.aspx</link><pubDate>Sun, 01 Nov 2009 22:08:19 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:92</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;In the RoleTailored client on a Page, the xRec does not contain a record when you are inserting new records into a sub page. Previously if you wanted to know where you had pressed F3 to insert a line you could take a look at xRec and would know which line you were on when you pressed F3.&lt;/p&gt;  &lt;p&gt;Unfortunately in the RTC the xRec is completely blank (when checking in the field validation triggers).&lt;/p&gt;  &lt;p&gt;Fortunately the xRec is not blank when it hits the onNewRecord() trigger so you can have a global variable on your form (I called mine g_MyXRec) and then assign it in that trigger, all is OK again.&lt;/p&gt;  &lt;p&gt;Here is an example of the OnNewRecord in the Page 46 Sales Order Subform…&lt;/p&gt;  &lt;p&gt;Type := xRec.Type;   &lt;br /&gt;CLEAR(ShortcutDimCode);    &lt;br /&gt;// My code added to allow me to see xRec --&amp;gt;    &lt;br /&gt;g_MyXRec := xRec;&lt;/p&gt;  &lt;p&gt;With this code in place, I can now use g_MyXRec to see which record I was on when I pressed Ctrl+Ins.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=92" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Programming/default.aspx">Programming</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Gotcha/default.aspx">Gotcha</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category></item><item><title>Custom Control for Reporting Services Reports</title><link>http://www.teachmenav.com/blogs/dave/archive/2009/10/19/custom-control-for-reporting-services-reports.aspx</link><pubDate>Mon, 19 Oct 2009 09:52:00 GMT</pubDate><guid isPermaLink="false">2902f03e-5b98-406b-a95e-124904271604:90</guid><dc:creator>David Roys</dc:creator><slash:comments>0</slash:comments><description>&lt;p&gt;I recently presented a session at Intergen Dynamics Day called &lt;em&gt;Dynamics NAV 2009 &amp;ndash; a &amp;ldquo;deep dive&amp;rdquo;&lt;/em&gt; in which I showed a custom control that displayed a Graph depicting the Aged Debt for a customer. In this post, I&amp;rsquo;ll tell you a little bit about how I created this control, how to use it, and of course provide a link to the downloads. The control is free for your own use but as usual it is provided without support or warranty. Here is an example of the control linking to the Customer List (there&amp;#39;s no sound on this video but I think it illustrates the control better than a picture).&lt;/p&gt;
&lt;p&gt;(Please visit the site to view this media)&lt;/p&gt;
&lt;div&gt;&lt;/div&gt;
&lt;p&gt;The control is based upon &lt;a target="_blank" href="http://blogs.msdn.com/freddyk/archive/2009/06/07/integration-to-virtual-earth-part-4-of-4.aspx"&gt;Freddy Kristiansen&amp;rsquo;s blog post&lt;/a&gt; and sample project for integration to Virtual Earth. In Freddy&amp;rsquo;s post, he creates a custom control that uses a browser to display a web page that he modifies dynamically to show the Bing Map location of a customer. This made me think that I could pinch Freddy&amp;rsquo;s code and with a few little tweaks, create a custom control that can display any URL in a mini-browser. Initially I was going to display a PDF, as I wanted to render a NAV 2009 report as a PDF and then display it in the browser control, but I couldn&amp;rsquo;t find a way to display the PDF without the Adobe Toolbar. Then I remembered I could create a Reporting Services report and use the ReportServer to display the report with no toolbar. Perfect!&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m amazed at not only how powerful these new custom controls are, but also how easy it was to create one (thanks to Freddy&amp;rsquo;s sample).&lt;/p&gt;
&lt;p&gt;I created the control in the VPC for NAV 2009 SP1 that &lt;a target="_blank" href="http://teachmenav.com/blogs/dave/archive/2009/09/29/microsoft-dynamics-nav-2009-sp1-vpc.aspx"&gt;can be downloaded from PartnerSource&lt;/a&gt;. To use this control yourself, you first need to create the stored procedure sp_CustAgingBand. This stored procedure takes a Customer No., the Company Name (as it is converted in SQL) and the date at which the graph should be based (since it is an aged debt graph we need a date).&lt;/p&gt;
&lt;p&gt;Next, you need to deploy the Reporting Services report. You can do this by opening the Dynamics Day Reports solution and deploying to the &lt;a href="http://nav-srv-01/ReportServer"&gt;http://nav-srv-01/ReportServer&lt;/a&gt; that you&amp;rsquo;ll find on the VPC image. &lt;/p&gt;
&lt;p&gt;Then copy the URLControl.dll to the RoleTailored Client\Add-ins\ directory, and register it with a public key token of a1b0b65d07f64054. I called mine SmallURLControl.&lt;/p&gt;
&lt;p&gt;Finally, I created a new Page called Customer Aged Debt Factbox (Page 90000) that uses the custom control and modified the Customer List page (page 22) to include my new Fact Box.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;ve deliberately kept this post short. If you want to know about any of these parts, leave me a comment and I can make a more detailed post at a later date.&lt;/p&gt;
&lt;p&gt;You can &lt;a target="_blank" href="http://teachmenav.com/forums/p/60/89.aspx#89"&gt;download the objects from here&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://www.teachmenav.com/aggbug.aspx?PostID=90" width="1" height="1"&gt;</description><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/.NET/default.aspx">.NET</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/NAV+2009+SP1/default.aspx">NAV 2009 SP1</category><category domain="http://www.teachmenav.com/blogs/dave/archive/tags/Custom+Controls/default.aspx">Custom Controls</category></item></channel></rss>
