<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>SysDictCoder</title>
	
	<link>http://sysdictcoder.com/blog</link>
	<description>Dynamics Ax stuff</description>
	<lastBuildDate>Wed, 13 Apr 2011 14:15:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/sysdictcoder" /><feedburner:info uri="sysdictcoder" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" /><item>
		<title>Changes in Ax 2012</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/NTvkeL4bGV8/</link>
		<comments>http://sysdictcoder.com/blog/changes-in-ax-2012/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 14:15:00 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=197</guid>
		<description><![CDATA[A book was just released called New, Changed, and Deprecated Features for Microsoft Dynamics AX 2012, available for download here. Required reading for Ax folks if you ask me. (via mfp)]]></description>
			<content:encoded><![CDATA[<p>A book was just released called <em>New, Changed, and Deprecated Features for Microsoft Dynamics AX 2012</em>, available for download <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=d38bb877-7cf8-400e-8a50-47d4ebbaf4a6&#038;displaylang=en">here</a>.  Required reading for Ax folks if you ask me.</p>
<p>(via <a href="http://blogs.msdn.com/b/mfp/archive/2011/04/13/new-changed-and-deprecated-features-for-microsoft-dynamics-ax-2012.aspx">mfp</a>)</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/NTvkeL4bGV8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/changes-in-ax-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/changes-in-ax-2012/</feedburner:origLink></item>
		<item>
		<title>On hand inventory in code</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/i1-r1XqF-SE/</link>
		<comments>http://sysdictcoder.com/blog/on-hand-inventory-in-code/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 22:04:13 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=167</guid>
		<description><![CDATA[Inventory in Ax is quite important. Often developers need to find out what the stock levels are in code. It&#8217;s tempting to write a query directly on the InventSum table and be done with it. This is usually not a good idea. If your code needs to deal with different inventory dimensions or you need [...]]]></description>
			<content:encoded><![CDATA[<p>Inventory in Ax is quite important.  Often developers need to find out what the stock levels are in code.  It&#8217;s tempting to write a query directly on the InventSum table and be done with it.  This is usually not a good idea.  If your code needs to deal with different inventory dimensions or you need to aggregate results on some random dimension, things can get complicated.</p>
<p>The good news is that there in standard Ax there already is a class to help you with this: InventDimOnHand.  Many people have heard about it but don&#8217;t really know how to use it.  It&#8217;s actually not that hard.  Recently for a modification I had to get hold of physically available stock of an item per location.  Naturally I ended up using InventDimOnHand to avoid getting lost in complex queries.</p>
<p>As an example I have made a simplified version of it.  Try running it in the CEU company of the Contoso demo database.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> demoInventOnHand<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    InventDimOnHand         onHand;
    InventDimOnHandIterator iter;
    InventDimOnHandMember   member;
&nbsp;
    ItemId                  itemId;
    InventDim               inventDimCrit;
    InventDimParm           inventDimParmCrit<span style="color: #00007f;">,</span> inventDimParmOnHandLevel;
&nbsp;
    InventDim               inventDim;
&nbsp;
    InventDimOnHandLevel    level;
    ;
&nbsp;
    itemId <span style="color: #00007f;">=</span> <span style="color: #ff0000;">'1509'</span>;
&nbsp;
    <span style="color: #007f00;">// Known dimensions</span>
    inventDimCrit.<span style="color: #000000;">InventLocationId</span> <span style="color: #00007f;">=</span> <span style="color: #ff0000;">'21'</span>;
    inventDimCrit <span style="color: #00007f;">=</span> InventDim<span style="color: #00007f;">::</span><span style="color: #000000;">findOrCreate</span><span style="color: #000000;">&#40;</span>inventDimCrit<span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #007f00;">// Determine which of the known dimensions to use</span>
    inventDimParmCrit.<span style="color: #000000;">InventLocationIdFlag</span> <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span>;
&nbsp;
    level <span style="color: #00007f;">=</span> InventDimOnHandLevel<span style="color: #00007f;">::</span><span style="color: #000000;">DimParm</span>;
&nbsp;
    <span style="color: #007f00;">// Only matters for level DimParm.  Determines the level of detail returned</span>
    inventDimParmOnHandLevel.<span style="color: #000000;">ItemIdFlag</span> <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span>;
    inventDimParmOnHandLevel.<span style="color: #000000;">InventLocationIdFlag</span> <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span>;
    inventDimParmOnHandLevel.<span style="color: #000000;">WMSLocationIdFlag</span> <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span>;
    inventDimParmOnHandLevel.<span style="color: #000000;">InventBatchIdFlag</span> <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span>;
&nbsp;
    onHand <span style="color: #00007f;">=</span> InventDimOnHand<span style="color: #00007f;">::</span><span style="color: #000000;">newAvailPhysical</span><span style="color: #000000;">&#40;</span>itemId<span style="color: #00007f;">,</span> inventDimCrit<span style="color: #00007f;">,</span> InventDimParmCrit<span style="color: #00007f;">,</span> level<span style="color: #00007f;">,</span> inventDimParmOnHandLevel<span style="color: #000000;">&#41;</span>;
&nbsp;
    iter <span style="color: #00007f;">=</span> onHand.<span style="color: #000000;">onHandIterator</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #0000ff;">while</span> <span style="color: #000000;">&#40;</span>iter.<span style="color: #000000;">more</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        member <span style="color: #00007f;">=</span> iter.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        inventDim <span style="color: #00007f;">=</span> InventDim<span style="color: #00007f;">::</span><span style="color: #000000;">find</span><span style="color: #000000;">&#40;</span>member.<span style="color: #000000;">parmInventDimId</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        info<span style="color: #000000;">&#40;</span>con2str<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>member.<span style="color: #000000;">parmItemId</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> inventDim.<span style="color: #000000;">inventLocationId</span><span style="color: #00007f;">,</span> inventDim.<span style="color: #000000;">wMSLocationId</span><span style="color: #00007f;">,</span> inventDim.<span style="color: #000000;">inventBatchId</span><span style="color: #00007f;">,</span> member.<span style="color: #000000;">parmInventQty</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        iter.<span style="color: #0000ff;">next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'Done'</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This prints a list of the available stock per batch number of the item in warehouse 21.  If you change the level to Item or comment out lines for the WMS location and batch flags, you will get the total stock for the item in the warehouse.   </p>
<p>Basically the first two parameters of newAvailPhysical() contain the item and dimensions for which you want to find the inventory.  The InventDimParmCrit parameter determines on which of the known dimensions should be filtered during the lookup.  This means it is possible to ignore values in InventDimCrit or force checks on empty values.</p>
<p>The last two parameters determine the level of detail of the stock.  In this case each batch of this item in warehouse 21 is reported.  You can check this in the on-hand inventory screen.  </p>
<p>The InventDimOnHand class then uses a couple of other classes like InventDimOnHandMember and InventDimOnHandIterator to make it possible to get the actual values.</p>
<p>Feel free to change the values of the parameters passed to availPhysical() to see what happens.  It is also possible to get something other than the physically available stock.  Check out the other functions on the class. </p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/i1-r1XqF-SE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/on-hand-inventory-in-code/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/on-hand-inventory-in-code/</feedburner:origLink></item>
		<item>
		<title>Deleting items from a list</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/BPI8S7tsN58/</link>
		<comments>http://sysdictcoder.com/blog/deleting-items-from-a-list/#comments</comments>
		<pubDate>Wed, 26 Jan 2011 20:09:51 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=176</guid>
		<description><![CDATA[Just a quick one to point out a common pitfall when working with list objects. To remove objects from a list you need to use an iterator. In X++ iterators require the developer to write a loop with calls to more() and next() to check if there are any elements left and make iterator advance [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick one to point out a common pitfall when working with list objects.  To remove objects from a list you need to use an iterator.  </p>
<p>In X++ iterators require the developer to write a loop with calls to more() and next() to check if there are any elements left and make iterator advance to the next element.</p>
<p>Not so when you&#8217;re going to delete elements from the list.  A call to delete() also advances to the next available element.  It makes sense, but if you forget it could make you scratch your head for a few minutes.</p>
<p>So don&#8217;t write what I first wrote:</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">    list <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> List<span style="color: #000000;">&#40;</span>Types<span style="color: #00007f;">::</span><span style="color: #000000;">String</span><span style="color: #000000;">&#41;</span>;
    list.<span style="color: #000000;">addEnd</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'a'</span><span style="color: #000000;">&#41;</span>; list.<span style="color: #000000;">addEnd</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'b'</span><span style="color: #000000;">&#41;</span>; list.<span style="color: #000000;">addEnd</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'c'</span><span style="color: #000000;">&#41;</span>; list.<span style="color: #000000;">addEnd</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'d'</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    iter <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> ListIterator<span style="color: #000000;">&#40;</span>list<span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">while</span> <span style="color: #000000;">&#40;</span>iter.<span style="color: #000000;">more</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        value <span style="color: #00007f;">=</span> iter.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #007f00;">// do a real check</span>
        <span style="color: #000000;">&#123;</span>
            iter.<span style="color: #000000;">delete</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        iter.<span style="color: #0000ff;">next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
&nbsp;
    info<span style="color: #000000;">&#40;</span>list.<span style="color: #000000;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>But rather do this:</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">    <span style="color: #0000ff;">while</span> <span style="color: #000000;">&#40;</span>iter.<span style="color: #000000;">more</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        value <span style="color: #00007f;">=</span> iter.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">true</span><span style="color: #000000;">&#41;</span> <span style="color: #007f00;">// check value</span>
        <span style="color: #000000;">&#123;</span>
            iter.<span style="color: #000000;">delete</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
        <span style="color: #0000ff;">else</span>
        <span style="color: #000000;">&#123;</span>
            iter.<span style="color: #0000ff;">next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    info<span style="color: #000000;">&#40;</span>list.<span style="color: #000000;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>Either do a delete() or a next().  Not both.  The same goes for maps and sets.</p>
<p>And by the way, if you want to do anything other than delete elements it&#8217;s highly recommended you use enumerators instead of iterators.  The reason is explained <a href="http://msdn.microsoft.com/en-us/library/aa678424.aspx">here on MSDN</a>.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/BPI8S7tsN58" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/deleting-items-from-a-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/deleting-items-from-a-list/</feedburner:origLink></item>
		<item>
		<title>Fix for long AOS startup time</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/pNXPu34Jh0E/</link>
		<comments>http://sysdictcoder.com/blog/fix-for-long-aos-startup-time/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 05:30:28 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Tips & tricks]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=155</guid>
		<description><![CDATA[When you&#8217;re starting an AOS you may notice it takes a very long time before the service gets the status Started. A possible cause is left-over data in the SysClientSessions table. When starting up, the AOS seems to check if the client is still around somewhere for each record. I have noticed that not it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>When you&#8217;re starting an AOS you may notice it takes a very long time before the service gets the status Started.  A possible cause is left-over data in the SysClientSessions table.  When starting up, the AOS seems to check if the client is still around somewhere for each record.  </p>
<p>I have noticed that not it&#8217;s not always cleaned up properly after an AOS is shut down. If an AOS is acting up and needs to be restarted anyway I check the table on SQL Server and delete the client records before restarting the service.  </p>
<p>Don&#8217;t just do this if multiple AOSes are set up for the same application.  All instances should be shut down before cleaning up data like this.</p>
<p>Unfortunately I haven&#8217;t yet figured out how records get stuck in that table after a graceful shutdown in the first place.  Of course, if it crashes the sessions won&#8217;t be erased either.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/pNXPu34Jh0E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/fix-for-long-aos-startup-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/fix-for-long-aos-startup-time/</feedburner:origLink></item>
		<item>
		<title>Of arrays and methods</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/rUS9ZQOb9ks/</link>
		<comments>http://sysdictcoder.com/blog/of-arrays-and-methods-2/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 05:30:19 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=161</guid>
		<description><![CDATA[In X++ arrays and methods don&#8217;t mix well. You can write a function that takes a parameter as an input value like this: void arrayInput&#40;str values&#91;&#93;&#41; &#123; int i; ; &#160; for &#40;i=1; i&#60;=dimOf&#40;values&#41;; ++i&#41; &#123; info&#40;values&#91;i&#93;&#41;; &#125; &#125; The compiler doesn&#8217;t object. Yet. Code calling this method just doesn&#8217;t compile. static void main&#40;Args _args&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>In X++ arrays and methods don&#8217;t mix well.  You can write a function that takes a parameter as an input value like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">void</span> arrayInput<span style="color: #008000;">&#40;</span>str values<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">int</span> i<span style="color: #008080;">;</span>
    <span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span>i<span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;=</span>dimOf<span style="color: #008000;">&#40;</span>values<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>i<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        info<span style="color: #008000;">&#40;</span>values<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The compiler doesn&#8217;t object.  Yet.  Code calling this method just doesn&#8217;t compile.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> main<span style="color: #008000;">&#40;</span>Args _args<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    DemoArray c <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> DemoArray<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    str v<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// ...</span>
    c.<span style="color: #007788;">arrayInput</span><span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>  <span style="color: #666666;">// Compiler says no</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Writing a method that returns an array doesn&#8217;t work either.  Because of the syntax of arrays in X++, with brackets following the variable name, there&#8217;s no decent way to define the return type.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">str<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> arrayOutput<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>  <span style="color: #666666;">// Try defining an array return type here...</span>
<span style="color: #008000;">&#123;</span>
    str v<span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
    <span style="color: #008080;">;</span>
&nbsp;
    v<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;a&quot;</span><span style="color: #008080;">;</span>
    v<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;ab&quot;</span><span style="color: #008080;">;</span>
    v<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">3</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;abc&quot;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> v<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>However, there is a way around it.  If you use an extended data type with several array elements the compiler won&#8217;t choke on it.<br />
<img src="http://sysdictcoder.com/blog/wp-content/uploads/valuearray.gif" alt="Screenshot of data type" title="Array of values" width="174" height="85" class="alignnone size-full wp-image-159" /><br />
The main drawback here is that the length of the array is fixed in the data type.  </p>
<p>With the data type the code looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">ValueArray arrayOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    ValueArray v;
    ;
&nbsp;
    v<span style="color: #000000;">&#91;</span><span style="color: #000000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #00007f;">=</span> <span style="color: #ff0000;">&quot;a&quot;</span>;
    v<span style="color: #000000;">&#91;</span><span style="color: #000000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #00007f;">=</span> <span style="color: #ff0000;">&quot;ab&quot;</span>;
    v<span style="color: #000000;">&#91;</span><span style="color: #000000;">3</span><span style="color: #000000;">&#93;</span> <span style="color: #00007f;">=</span> <span style="color: #ff0000;">&quot;abc&quot;</span>;
&nbsp;
    <span style="color: #0000ff;">return</span> v;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> arrayInput<span style="color: #000000;">&#40;</span>ValueArray values<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0000ff;">int</span> i;
    ;
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #000000;">&#40;</span>i<span style="color: #00007f;">=</span><span style="color: #000000;">1</span>; i<span style="color: #00007f;">&lt;=</span><span style="color: #0000ff;">dimOf</span><span style="color: #000000;">&#40;</span>values<span style="color: #000000;">&#41;</span>; <span style="color: #00007f;">++</span>i<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        info<span style="color: #000000;">&#40;</span>values<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> main<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    DemoArray c <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> DemoArray<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
    ValueArray v;
    ;
&nbsp;
    v <span style="color: #00007f;">=</span> c.<span style="color: #000000;">arrayOutput</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    c.<span style="color: #000000;">arrayInput</span><span style="color: #000000;">&#40;</span>v<span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It&#8217;s kind of weird but it works fine.  Obviously the runtime can handle more than the compiler and X++ syntax allow.  It&#8217;s a bit kludgy but it can save you a lot of work when confronted with legacy code.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/rUS9ZQOb9ks" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/of-arrays-and-methods-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/of-arrays-and-methods-2/</feedburner:origLink></item>
		<item>
		<title>Copy records</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/DbgHIyCgqGQ/</link>
		<comments>http://sysdictcoder.com/blog/copy-records-142/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 17:06:21 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=142</guid>
		<description><![CDATA[A while ago I wrote a simple function to compare records. If you want to do something else check out Patrik Luca&#8217;s copy function. Another example how to use reflection.]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote a simple function to <a href="http://sysdictcoder.com/blog/comparing-records/">compare records</a>.  If you want to do something else check out Patrik Luca&#8217;s <a href="http://patrikluca.blogspot.com/2010/04/x-code-snippet-copying-records.html">copy function</a>.  Another example how to use reflection.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/DbgHIyCgqGQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/copy-records-142/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/copy-records-142/</feedburner:origLink></item>
		<item>
		<title>Comparing records</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/3IW37fNgwlQ/</link>
		<comments>http://sysdictcoder.com/blog/comparing-records/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 09:35:01 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=55</guid>
		<description><![CDATA[Sometimes you need to know what&#8217;s the difference between records. I made a simple function to do just that. It&#8217;s an example of how to use reflection and field IDs on records. It takes two records and returns a container with the field IDs and the values from both records. For simplicity I used a [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to know what&#8217;s the difference between records.  I made a simple function to do just that.  It&#8217;s an example of how to use <a href="http://sysdictcoder.com/blog/reflection-with-the-dictionary/">reflection</a> and <a href="http://sysdictcoder.com/blog/tricks-with-xpp-embedded-sql/">field IDs on records</a>.</p>
<p>It takes two records and returns a container with the field IDs and the values from both records.  For simplicity I used a flattened container instead of more complicated data structures.  Feel free to replace it with nested containers or some kind of collection.</p>
<p>I added this to the class Global for easy access.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">container</span> compareRecords<span style="color: #000000;">&#40;</span>Common _record1<span style="color: #00007f;">,</span> Common _record2<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    SysDictTable    dictTable <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> SysDictTable<span style="color: #000000;">&#40;</span>_record1.<span style="color: #000000;">TableId</span><span style="color: #000000;">&#41;</span>;
    SysDictField    dictField;
    FieldId         fieldId<span style="color: #00007f;">,</span> extFieldId;
    <span style="color: #0000ff;">container</span>       ret;
    <span style="color: #0000ff;">int</span>             i<span style="color: #00007f;">,</span> j;
    ;
&nbsp;
    <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>_record1.<span style="color: #000000;">TableId</span> <span style="color: #00007f;">!=</span> _record2.<span style="color: #000000;">TableId</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">conNull</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #000000;">&#40;</span>i<span style="color: #00007f;">=</span><span style="color: #000000;">1</span>; i<span style="color: #00007f;">&lt;=</span>dictTable.<span style="color: #000000;">fieldCnt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #00007f;">++</span>i<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        fieldId <span style="color: #00007f;">=</span> dictTable.<span style="color: #000000;">fieldCnt2Id</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
        dictField <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> SysDictField<span style="color: #000000;">&#40;</span>_record1.<span style="color: #000000;">tableId</span><span style="color: #00007f;">,</span> fieldId<span style="color: #000000;">&#41;</span>;
&nbsp;
        <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #00007f;">!</span>dictField.<span style="color: #000000;">isSystem</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0000ff;">for</span> <span style="color: #000000;">&#40;</span>j<span style="color: #00007f;">=</span><span style="color: #000000;">1</span>; j<span style="color: #00007f;">&lt;=</span> dictField.<span style="color: #000000;">arraySize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>; <span style="color: #00007f;">++</span>j<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                extFieldId <span style="color: #00007f;">=</span> fieldId2Ext<span style="color: #000000;">&#40;</span>fieldId<span style="color: #00007f;">,</span> j<span style="color: #000000;">&#41;</span>;
&nbsp;
                <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>_record1.<span style="color: #000000;">&#40;</span>extFieldId<span style="color: #000000;">&#41;</span> <span style="color: #00007f;">!=</span> _record2.<span style="color: #000000;">&#40;</span>extFieldId<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    ret <span style="color: #00007f;">+=</span> <span style="color: #000000;">&#91;</span>extFieldId<span style="color: #00007f;">,</span> _record1.<span style="color: #000000;">&#40;</span>extFieldId<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> _record2.<span style="color: #000000;">&#40;</span>extFieldId<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>;
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> ret;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As you can see it only compares records of the same type and skips system fields (e.g. RecId).  Special care is taken to handle array fields correctly.</p>
<p>Using it is quite straightforward.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> demoCompareRecords<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    CustTable   custTable1 <span style="color: #00007f;">=</span> CustTable<span style="color: #00007f;">::</span><span style="color: #000000;">find</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'1101'</span><span style="color: #000000;">&#41;</span>; <span style="color: #007f00;">// CEE demo data</span>
    CustTable   custTable2 <span style="color: #00007f;">=</span> CustTable<span style="color: #00007f;">::</span><span style="color: #000000;">find</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'1102'</span><span style="color: #000000;">&#41;</span>; <span style="color: #007f00;">// CEE demo data</span>
&nbsp;
    <span style="color: #0000ff;">container</span>   con;
    <span style="color: #0000ff;">int</span>         i;
    ;
&nbsp;
    con <span style="color: #00007f;">=</span> Global<span style="color: #00007f;">::</span><span style="color: #000000;">compareRecords</span><span style="color: #000000;">&#40;</span>custTable1<span style="color: #00007f;">,</span> custTable2<span style="color: #000000;">&#41;</span>;
&nbsp;
    <span style="color: #0000ff;">for</span> <span style="color: #000000;">&#40;</span>i<span style="color: #00007f;">=</span><span style="color: #000000;">1</span>; i<span style="color: #00007f;">&lt;=</span><span style="color: #0000ff;">conLen</span><span style="color: #000000;">&#40;</span>con<span style="color: #000000;">&#41;</span>; i<span style="color: #00007f;">+=</span><span style="color: #000000;">3</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        info<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strFmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;%1: '%2' &lt;-&gt; '%3'&quot;</span>
                   <span style="color: #00007f;">,</span><span style="color: #0000ff;">fieldId2Name</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">tableNum</span><span style="color: #000000;">&#40;</span>CustTable<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">conPeek</span><span style="color: #000000;">&#40;</span>con<span style="color: #00007f;">,</span> i<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                   <span style="color: #00007f;">,</span><span style="color: #0000ff;">conPeek</span><span style="color: #000000;">&#40;</span>con<span style="color: #00007f;">,</span> i<span style="color: #00007f;">+</span><span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>
                   <span style="color: #00007f;">,</span><span style="color: #0000ff;">conPeek</span><span style="color: #000000;">&#40;</span>con<span style="color: #00007f;">,</span> i<span style="color: #00007f;">+</span><span style="color: #000000;">2</span><span style="color: #000000;">&#41;</span>
                   <span style="color: #000000;">&#41;</span>
             <span style="color: #000000;">&#41;</span>;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/3IW37fNgwlQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/comparing-records/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/comparing-records/</feedburner:origLink></item>
		<item>
		<title>Axapta timeline</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/4hzh1wj7Jgs/</link>
		<comments>http://sysdictcoder.com/blog/axapta-timeline/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 18:28:14 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=130</guid>
		<description><![CDATA[Ever wondered how Dynamics Ax came to be? Check out the timeline I found at DynamicsWorld.]]></description>
			<content:encoded><![CDATA[<p>Ever wondered how Dynamics Ax came to be?  Check out the <a href="http://www.dynamicsworld.co.uk/Dynamics-AX-Timeline.php">timeline</a> I found at DynamicsWorld.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/4hzh1wj7Jgs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/axapta-timeline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/axapta-timeline/</feedburner:origLink></item>
		<item>
		<title>Intrinsic function weirdness</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/CfDj_FIusrs/</link>
		<comments>http://sysdictcoder.com/blog/intrinsic-function-weirdness/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 08:21:15 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Bug]]></category>
		<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=127</guid>
		<description><![CDATA[Over at Dynamics Ax Daily I found a post about a compile error using tableNum() in a select statement. As mentioned there, the following code doesn&#8217;t compile. select extCodeTable where extCodeTable.ExtCodeTableId == tableNum&#40;CompanyInfo&#41; join extCodeValueTable where extCodeValueTable.ExtCodeId == extCodeTable.ExtCodeId; The compiler chokes on the call to tableNum(). I was surprised to see this, as I [...]]]></description>
			<content:encoded><![CDATA[<p>Over at <a href="http://axdaily.blogspot.com/">Dynamics Ax Daily</a> I found a post about a <a href="http://axdaily.blogspot.com/2010/02/intrinsic-functions-in-queries.html">compile error</a> using tableNum() in a select statement.</p>
<p>As mentioned there, the following code doesn&#8217;t compile.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">    <span style="color: #0000ff;">select</span> extCodeTable
        <span style="color: #0000ff;">where</span> extCodeTable.<span style="color: #000000;">ExtCodeTableId</span> <span style="color: #00007f;">==</span> <span style="color: #0000ff;">tableNum</span><span style="color: #000000;">&#40;</span>CompanyInfo<span style="color: #000000;">&#41;</span>
    <span style="color: #0000ff;">join</span> extCodeValueTable
        <span style="color: #0000ff;">where</span> extCodeValueTable.<span style="color: #000000;">ExtCodeId</span> <span style="color: #00007f;">==</span> extCodeTable.<span style="color: #000000;">ExtCodeId</span>;</pre></div></div>

<p>The compiler chokes on the call to tableNum().  I was surprised to see this, as I could have sworn that I have used tableNum() in select statements before.  As it turns out it does compile in some cases.</p>
<p>It compiles without the join.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">    <span style="color: #0000ff;">select</span> extCodeTable
        <span style="color: #0000ff;">where</span> extCodeTable.<span style="color: #000000;">ExtCodeTableId</span> <span style="color: #00007f;">==</span> <span style="color: #0000ff;">tableNum</span><span style="color: #000000;">&#40;</span>CompanyInfo<span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>It also works if you add another where clause after tableNum().</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">    <span style="color: #0000ff;">select</span> extCodeTable
        <span style="color: #0000ff;">where</span> extCodeTable.<span style="color: #000000;">ExtCodeTableId</span> <span style="color: #00007f;">==</span> <span style="color: #0000ff;">tableNum</span><span style="color: #000000;">&#40;</span>CompanyInfo<span style="color: #000000;">&#41;</span>
             <span style="color: #00007f;">&amp;&amp;</span> extCodeTable.<span style="color: #000000;">RecId</span> <span style="color: #00007f;">!=</span> <span style="color: #000000;">0</span>
    <span style="color: #0000ff;">join</span> extCodeValueTable
        <span style="color: #0000ff;">where</span> extCodeValueTable.<span style="color: #000000;">ExtCodeId</span> <span style="color: #00007f;">==</span> extCodeTable.<span style="color: #000000;">ExtCodeId</span>;</pre></div></div>

<p>And using a non-intrinsic function works too.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;">    <span style="color: #0000ff;">select</span> extCodeTable
        <span style="color: #0000ff;">where</span> extCodeTable.<span style="color: #000000;">ExtCodeTableId</span> <span style="color: #00007f;">==</span> <span style="color: #0000ff;">str2int</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;1234&quot;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #0000ff;">join</span> extCodeValueTable
        <span style="color: #0000ff;">where</span> extCodeValueTable.<span style="color: #000000;">ExtCodeId</span> <span style="color: #00007f;">==</span> extCodeTable.<span style="color: #000000;">ExtCodeId</span>;</pre></div></div>

<p>This example doesn&#8217;t make much sense with regards to business logic but it does compile.</p>
<p>I&#8217;m guessing this is a bug in the compiler.  As far as I can tell it only fails when you use an intrinsic function before a join clause.  Until it&#8217;s fixed just use a variable or throw in another where clause to check for RecId != 0.  Since all records have a RecId it won&#8217;t affect the results you get back.  This happens in Ax 4.0 and 2009.</p>
<p>All intrinsic functions are listed on <a href="http://msdn.microsoft.com/en-us/library/dd252591.aspx">MSDN</a>.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/CfDj_FIusrs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/intrinsic-function-weirdness/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/intrinsic-function-weirdness/</feedburner:origLink></item>
		<item>
		<title>Tricks with X++ embedded SQL</title>
		<link>http://feedproxy.google.com/~r/sysdictcoder/~3/lHdqUyXRv6I/</link>
		<comments>http://sysdictcoder.com/blog/tricks-with-xpp-embedded-sql/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 16:26:40 +0000</pubDate>
		<dc:creator>Björn</dc:creator>
				<category><![CDATA[Dynamics Ax (Axapta)]]></category>
		<category><![CDATA[Tips & tricks]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://sysdictcoder.com/blog/?p=99</guid>
		<description><![CDATA[There are some tricks that you can do in X++ SQL. They&#8217;re not really well known because they&#8217;re not suited for normal use and there are not many clues in the editor that they exist. But they do come in handy every now and then. Getting data without declaring a table variable It&#8217;s possible to [...]]]></description>
			<content:encoded><![CDATA[<p>There are some tricks that you can do in X++ SQL.  They&#8217;re not really well known because they&#8217;re not suited for normal use and there are not many clues in the editor that they exist.  But they do come in handy every now and then.</p>
<h2>Getting data without declaring a table variable</h2>
<p>It&#8217;s possible to get data from the database without declaring any table variables.  It goes something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Job3<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #007f00;">// No variables!</span>
    ;
&nbsp;
    <span style="color: #0000ff;">print</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff;">select</span> CustTable<span style="color: #000000;">&#41;</span>.<span style="color: #000000;">AccountNum</span>;
    <span style="color: #0000ff;">pause</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Note the parentheses around the select statement.  This tells the compiler to create a temporary, anonymous buffer to hold the record.  The select statement uses the exact table name and is immediately followed by a field name to get a value from a field.  </p>
<p>If you use this there&#8217;s no Intellisense to help you look up the field name because the editor doesn&#8217;t know the type of the anonymous buffer.</p>
<p>This technique is often used in exist() methods on tables.</p>
<h2>Getting a value from a field if you only know the field ID</h2>
<p>Sometimes you don&#8217;t know the exact field name but you do know a field ID.  Even in cases like this it&#8217;s possible to write an X++ SQL statement without knowing any field names.</p>
<p>Take a look at this example.</p>

<div class="wp_syntax"><div class="code"><pre class="xpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> Job4<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    CustTable   custTable;
    FieldId     fieldId;
    ;
&nbsp;
    fieldId <span style="color: #00007f;">=</span> <span style="color: #0000ff;">fieldNum</span><span style="color: #000000;">&#40;</span>CustTable<span style="color: #00007f;">,</span> AccountNum<span style="color: #000000;">&#41;</span>; <span style="color: #007f00;">// This could be passed as a method parameter</span>
&nbsp;
    <span style="color: #0000ff;">select</span> custTable; <span style="color: #007f00;">// Get first record</span>
&nbsp;
    <span style="color: #0000ff;">print</span> custTable.<span style="color: #000000;">&#40;</span>fieldId<span style="color: #000000;">&#41;</span>; <span style="color: #007f00;">// Print account number</span>
&nbsp;
    <span style="color: #0000ff;">select</span> custTable
        <span style="color: #0000ff;">where</span> custTable.<span style="color: #000000;">&#40;</span>fieldId<span style="color: #000000;">&#41;</span> <span style="color: #00007f;">==</span> <span style="color: #ff0000;">'1101'</span>;  <span style="color: #007f00;">// Where clause based on field ID</span>
&nbsp;
    <span style="color: #0000ff;">print</span> custTable.<span style="color: #000000;">Name</span>;
    <span style="color: #0000ff;">pause</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It&#8217;s possible to use field IDs to retrieve values as well as use them in a where clause.  Again parentheses are the key.  Instead of writing a regular field name, wrap the ID in parentheses and you&#8217;re done.  This makes it possible create generic code to handle any table and field without knowing the types at compile time.  If you dig around in the classes for importing and exporting data you&#8217;ll find some examples.</p>
<img src="http://feeds.feedburner.com/~r/sysdictcoder/~4/lHdqUyXRv6I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://sysdictcoder.com/blog/tricks-with-xpp-embedded-sql/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://sysdictcoder.com/blog/tricks-with-xpp-embedded-sql/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 3.313 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-17 06:14:51 -->

