<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Art Of Creation - Dynamics AX Blog &#187; Dynamics AX</title>
	<atom:link href="http://www.artofcreation.be/tag/dynamics-ax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.artofcreation.be</link>
	<description>The everyday life of a Dynamics AX developer</description>
	<lastBuildDate>Thu, 02 Feb 2012 12:20:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Microsoft Dynamics Salary Survey 2012</title>
		<link>http://www.artofcreation.be/2012/01/17/microsoft-dynamics-salary-survey-2012/</link>
		<comments>http://www.artofcreation.be/2012/01/17/microsoft-dynamics-salary-survey-2012/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 19:20:37 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Nigel Frank]]></category>
		<category><![CDATA[Salary survey]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1471</guid>
		<description><![CDATA[Hi all! Wondering if you&#8217;re getting the right salary? Nigel Frank is organizing its yearly salary survey for Dynamics professionals. You&#8217;ll get a copy of the results for free if you take part in the survey, and you can also win some prizes. Just click the banner to take part in the survey.]]></description>
			<content:encoded><![CDATA[<p>Hi all!</p>
<p>Wondering if you&#8217;re getting the right salary?<br />
<a href="http://www.nigelfrank.com/">Nigel Frank</a> is organizing its yearly salary survey for Dynamics professionals. </p>
<p>You&#8217;ll get a copy of the results for free if you take part in the survey, and you can also win some prizes.<br />
<a href="http://survey.nigelfrank.com/en/microsoft-dynamics-salary-survey-2012.html"><br />
<img src="http://www.artofcreation.be/wp-content/uploads/Header_EN.jpg" alt="Nigal Frank Salary Survey" title="Nigal Frank Salary Survey" width="580" height="175" class="aligncenter size-full wp-image-1475" /></a></p>
<p>Just click the banner to take part in the survey.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2012/01/17/microsoft-dynamics-salary-survey-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AX Technical Conference 2011: Session Recordings (Now available)</title>
		<link>http://www.artofcreation.be/2012/01/17/ax-technical-conference-2011-session-recordings-now-available/</link>
		<comments>http://www.artofcreation.be/2012/01/17/ax-technical-conference-2011-session-recordings-now-available/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 09:31:20 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Technical conference]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1467</guid>
		<description><![CDATA[The session recordings and slides from the Technical Conference in Nice 2011 are available here: https://mbs.microsoft.com/partnersource/newsevents/news/MSDAXTechnicalConf2011Recordings]]></description>
			<content:encoded><![CDATA[<p>The session recordings and slides from the Technical Conference in Nice 2011 are available here:<br />
<a href="https://mbs.microsoft.com/partnersource/newsevents/news/MSDAXTechnicalConf2011Recordings ">https://mbs.microsoft.com/partnersource/newsevents/news/MSDAXTechnicalConf2011Recordings</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2012/01/17/ax-technical-conference-2011-session-recordings-now-available/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Data migration: Importing the InventItemGroupForm Table</title>
		<link>http://www.artofcreation.be/2011/11/08/data-migration-importing-the-inventitemgroupform-table/</link>
		<comments>http://www.artofcreation.be/2011/11/08/data-migration-importing-the-inventitemgroupform-table/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 10:23:53 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Data conversion]]></category>
		<category><![CDATA[Data migration]]></category>
		<category><![CDATA[Job]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1421</guid>
		<description><![CDATA[Hi everyone :-). I am tasked with doing data migration for a project that is about to go live. One of the things that have to be converted are item groups (InventItemGroup) and their linked dimensions (InventItemGroupForm). Importing the InventItemGroup table is easy, but InventItemGroupForm is a little bit trickier. There is a job below [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone :-). </p>
<p>I am tasked with doing data migration for a project that is about to go live. One of the things that have to be converted are item groups (InventItemGroup) and their linked dimensions (InventItemGroupForm). </p>
<p>Importing the InventItemGroup table is easy, but InventItemGroupForm is a little bit trickier.<br />
There is a job below that shows how to fill in the LedgerDimension field on the InventItemGroupForm table. I&#8217;m not saying I completely understand the new dimension framework, but this method worked for me, and I hope it helps you when you have to do the same thing. </p>
<p>You will notice that you won&#8217;t be able to import the InventItemGroupForm table with the excel add-on. You&#8217;ll have to use a custom job (or make you own import framework like I did). </p>
<p>This white paper can help too: <a href="http://technet.microsoft.com/en-us/library/hh272858.aspx">Implementing the Account and Financial Dimensions Framework (White paper)</a></p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> klforDimensionTest<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #007f00; font-style: italic;">/* input */</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// the InventItemGroup record we want to set accounts for</span><br />
&nbsp; &nbsp; InventItemGroup &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inventItemGroup <span style="color: #00007f;">=</span> InventItemGroup<span style="color: #00007f;">::</span><span style="color: #000000;">find</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Car Audio&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// the main account we want to link to our InventItemGroup</span><br />
&nbsp; &nbsp; MainAccountNum &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mainAccountNum <span style="color: #00007f;">=</span> <span style="color: #ff0000;">&quot;0107&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// The account type we are setting</span><br />
&nbsp; &nbsp; InventAccountType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inventAccountType <span style="color: #00007f;">=</span> InventAccountType<span style="color: #00007f;">::</span><span style="color: #000000;">InventIssue</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// the dimension group of the account type</span><br />
&nbsp; &nbsp; ItemGroupLedgerDimensionGroup &nbsp; &nbsp; &nbsp; itemGroupLedgerDimensionGroup <span style="color: #00007f;">=</span> ItemGroupLedgerDimensionGroup<span style="color: #00007f;">::</span><span style="color: #000000;">Inventory</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00; font-style: italic;">/* declarations */</span><br />
&nbsp; &nbsp; Ledger &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ledger;<br />
&nbsp; &nbsp; MainAccount &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mainAccount;<br />
&nbsp; &nbsp; DimensionAttributeValueCombination &nbsp;dimensionAttributeValueCombination;<br />
&nbsp; &nbsp; DimensionAttributeValue &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dimAttributeValue;<br />
&nbsp; &nbsp; DimensionAttribute &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dimAttribute;<br />
&nbsp; &nbsp; DimensionStorage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dimStorage;<br />
&nbsp; &nbsp; RecId &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hierarchyRecId;<br />
<br />
&nbsp; &nbsp; DimensionStorageSegment &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dimensionStorageSegment;<br />
&nbsp; &nbsp; InventItemGroupForm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>inventItemGroup.<span style="color: #000000;">RecId</span> <span style="color: #00007f;">==</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">throw</span> error<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;InventItemGroup not found&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// check if inventItemGroupForm record exists</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">firstOnly</span> <span style="color: #0000ff;">forUpdate</span> inventItemGroupForm<br />
&nbsp; &nbsp; <span style="color: #0000ff;">where</span> &nbsp;inventItemGroupForm.<span style="color: #000000;">ItemGroupId</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00007f;">==</span> inventItemGroup.<span style="color: #000000;">ItemGroupId</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">&amp;&amp;</span> inventItemGroupForm.<span style="color: #000000;">InventAccountType</span> &nbsp; &nbsp;<span style="color: #00007f;">==</span> inventAccountType<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">&amp;&amp;</span> inventItemGroupForm.<span style="color: #000000;">LedgerDimensionGroup</span> <span style="color: #00007f;">==</span> itemGroupLedgerDimensionGroup;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span><span style="color: #00007f;">!</span>inventItemGroupForm<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// record does not exists, initialize it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">initValue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">ItemGroupId</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">=</span> inventItemGroup.<span style="color: #000000;">ItemGroupId</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">InventAccountType</span> &nbsp; &nbsp; &nbsp; <span style="color: #00007f;">=</span> inventAccountType;<br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">LedgerDimensionGroup</span> &nbsp; &nbsp;<span style="color: #00007f;">=</span> itemGroupLedgerDimensionGroup;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get the ledger record for the current company</span><br />
&nbsp; &nbsp; ledger <span style="color: #00007f;">=</span> Ledger<span style="color: #00007f;">::</span><span style="color: #000000;">findByLegalEntity</span><span style="color: #000000;">&#40;</span>CompanyInfo<span style="color: #00007f;">::</span><span style="color: #000000;">current</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// lookup main account record</span><br />
&nbsp; &nbsp; mainAccount <span style="color: #00007f;">=</span> MainAccount<span style="color: #00007f;">::</span><span style="color: #000000;">findByMainAccountId</span><span style="color: #000000;">&#40;</span>mainAccountNum<span style="color: #00007f;">,</span> <span style="color: #0000ff;">false</span><span style="color: #00007f;">,</span> ledger.<span style="color: #000000;">ChartOfAccounts</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>mainAccount.<span style="color: #000000;">RecId</span> <span style="color: #00007f;">==</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">throw</span> error<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;MainAccount not found&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// check if DAVC exists</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">firstOnly</span> dimensionAttributeValueCombination<br />
&nbsp; &nbsp; <span style="color: #0000ff;">where</span> dimensionAttributeValueCombination.<span style="color: #000000;">MainAccount</span> <span style="color: #00007f;">==</span> mainAccount.<span style="color: #000000;">RecId</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">&amp;&amp;</span> dimensionAttributeValueCombination.<span style="color: #000000;">AccountStructure</span> <span style="color: #00007f;">==</span> <span style="color: #000000;">0</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #00007f;">&amp;&amp;</span> dimensionAttributeValueCombination.<span style="color: #000000;">LedgerDimensionType</span> <span style="color: #00007f;">==</span> LedgerDimensionType<span style="color: #00007f;">::</span><span style="color: #000000;">DefaultAccount</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// when the DAVC does not exist, create it</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>dimensionAttributeValueCombination.<span style="color: #000000;">RecId</span> <span style="color: #00007f;">==</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007f00;">// Cache the dimension attribute that represents the Main account</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">select</span> <span style="color: #0000ff;">firstonly</span> <span style="color: #00007f;">*</span> <span style="color: #0000ff;">from</span> dimAttribute <span style="color: #0000ff;">where</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dimAttribute.<span style="color: #000000;">RecId</span> <span style="color: #00007f;">==</span> DimensionAttribute<span style="color: #00007f;">::</span><span style="color: #000000;">getMainAccountDimensionAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// Lookup the DAV backing the main account instance</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dimAttributeValue <span style="color: #00007f;">=</span> DimensionAttributeValue<span style="color: #00007f;">::</span><span style="color: #000000;">findByDimensionAttributeAndEntityInst</span><span style="color: #000000;">&#40;</span>dimAttribute.<span style="color: #000000;">RecId</span><span style="color: #00007f;">,</span> mainAccount.<span style="color: #000000;">RecId</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">false</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// lookup the hierarchy for the default acount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; hierarchyRecId <span style="color: #00007f;">=</span> DimensionHierarchy<span style="color: #00007f;">::</span><span style="color: #000000;">getHierarchyIdByHierarchyType</span><span style="color: #000000;">&#40;</span>DimensionHierarchyType<span style="color: #00007f;">::</span><span style="color: #000000;">DefaultAccount</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// create new storage</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dimStorage <span style="color: #00007f;">=</span> DimensionStorage<span style="color: #00007f;">::</span><span style="color: #000000;">construct</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// add the default account structure hierarchy</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dimStorage.<span style="color: #000000;">addAccountStructure</span><span style="color: #000000;">&#40;</span>hierarchyRecId<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// create storage segment for the value</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dimensionStorageSegment <span style="color: #00007f;">=</span> DimensionStorageSegment<span style="color: #00007f;">::</span><span style="color: #000000;">construct</span><span style="color: #000000;">&#40;</span>mainAccountNum<span style="color: #00007f;">,</span> dimAttributeValue.<span style="color: #000000;">RecId</span><span style="color: #00007f;">,</span> dimAttributeValue.<span style="color: #000000;">HashKey</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// add the segment to the storage</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dimStorage.<span style="color: #000000;">setSegment</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">1</span><span style="color: #00007f;">,</span> dimensionStorageSegment<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// save storage as default account and get the record</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dimensionAttributeValueCombination <span style="color: #00007f;">=</span> DimensionAttributeValueCombination<span style="color: #00007f;">::</span><span style="color: #000000;">find</span><span style="color: #000000;">&#40;</span>dimStorage.<span style="color: #000000;">saveAsDefaultAccount</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// set the ledgerdimension reference field</span><br />
&nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">LedgerDimension</span> <span style="color: #00007f;">=</span> dimensionAttributeValueCombination.<span style="color: #000000;">RecId</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// call modifiedfield voor ledgerdimension field to sync inventPosting</span><br />
&nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">modifiedField</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">fieldNum</span><span style="color: #000000;">&#40;</span>InventItemGroupForm<span style="color: #00007f;">,</span> LedgerDimension<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">ttsBegin</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>inventItemGroupForm.<span style="color: #000000;">recid</span> <span style="color: #00007f;">==</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// insert if this is a new record</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">insert</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">else</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// update existing record</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; inventItemGroupForm.<span style="color: #000000;">update</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">ttsCommit</span>;<br />
<br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Done&quot;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Comments with ideas / insights / improvements are welcome as always. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/11/08/data-migration-importing-the-inventitemgroupform-table/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>See you at Technical Conference in Nice (Nov 14-16)</title>
		<link>http://www.artofcreation.be/2011/11/07/see-you-at-technical-conference-in-nice-nov-14-16/</link>
		<comments>http://www.artofcreation.be/2011/11/07/see-you-at-technical-conference-in-nice-nov-14-16/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 20:17:46 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Technical conference]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1411</guid>
		<description><![CDATA[Hi everyone, Together with some colleagues, I will be attending the Technical Conference in Nice next week. I&#8217;m very exited, as this is a first for me (but hopefully not last). I will bring you the news when I get back. See you there!]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.artofcreation.be/wp-content/uploads/AXTechConference_04.png" alt="AXTechConference banner" title="AXTechConference_04" class="aligncenter size-full wp-image-1412" /></p>
<p>Hi everyone, </p>
<p>Together with some colleagues, I will be attending the <a href="http://www.microsoft.com/dynamics/dynamicsaxtechnicalconference2011/">Technical Conference in Nice</a> next week.<br />
I&#8217;m very exited, as this is a first for me (but hopefully not last). </p>
<p>I will bring you the news when I get back.<br />
See you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/11/07/see-you-at-technical-conference-in-nice-nov-14-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AX2012: SysOperation part 3: SysOperationAutomaticUIBuilder</title>
		<link>http://www.artofcreation.be/2011/08/24/ax2012-sysoperation-part-3-sysoperationautomaticuibuilder/</link>
		<comments>http://www.artofcreation.be/2011/08/24/ax2012-sysoperation-part-3-sysoperationautomaticuibuilder/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 10:00:00 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[SysOperation]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1279</guid>
		<description><![CDATA[Hi everyone. This is the third and final part in my series of posts about SysOperation (at least for now). You can find part 1 here and part 2 here. I will demonstrate how to override methods on the dialog (in this case modified()), and how to read and set properties of controls. For the [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone. </p>
<p>This is the third and final part in my series of posts about SysOperation (at least for now). You can find part 1 <a href="http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/">here </a>and part 2 <a href="http://www.artofcreation.be/2011/08/23/ax2012-sysoperation-part-2-sysoperationservicecontroller/">here</a>. </p>
<p>I will demonstrate how to override methods on the dialog (in this case modified()), and how to read and set properties of controls. </p>
<p>For the sake of this demo, we will add a checkbox to the dialog that will allow us to set the <strong>enabled </strong>property of the date control.<br />
It should look like this:<br />
<img src="http://www.artofcreation.be/wp-content/uploads/CheckboxChecked.png" alt="" title="CheckboxChecked" width="620" height="320" class="aligncenter size-full wp-image-1370" /></p>
<h3>1. Modify the data contract</h3>
<p>We will need to modify the data contract so a checkbox is displayed on the dialog that we can use to enable or disable the date control. </p>
<p>Add this variable to the class declaration of the <strong>KlForCustTesterDataContract </strong>class:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; NoYesId &nbsp; &nbsp; allowModifyDate;</div></div>
<p>Then add this method to that same data contract</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataMemberAttribute<span style="color: #00007f;">,</span><br />
SysOperationLabelAttribute<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;Enable date control&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">public</span> NoYesId parmAllowModifyDate<span style="color: #000000;">&#40;</span>NoYesId _allowModifyDate <span style="color: #00007f;">=</span> allowModifyDate<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; allowModifyDate <span style="color: #00007f;">=</span> _allowModifyDate;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> allowModifyDate;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>There&#8217;s nothing new here, we already did all of this in <a href="http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/">part 1</a></p>
<h3>2. Extending SysOperationAutomaticUIBuilder</h3>
<p>We will extend the SysOperationAutomaticUIBuilder class so we can override methods and properties of controls on our dialog. </p>
<p>First, create a new class, KlForCustTesterUIBuilder:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">class</span> KlForCustTesterUIBuilder <span style="color: #0000ff;">extends</span> SysOperationAutomaticUIBuilder<br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Things we will need in this class are:</p>
<ol>
<li>a variable for the date control</li>
<li>a variable for the new checkbox control</li>
<li>our data contract</li>
</ol>
<p>So we add these variables to the class declaration:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">class</span> KlForCustTesterUIBuilder <span style="color: #0000ff;">extends</span> SysOperationAutomaticUIBuilder<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; DialogField &nbsp; &nbsp; dialogFieldAllowModifyDate;<br />
&nbsp; &nbsp; DialogField &nbsp; &nbsp; dialogFieldTransDate;<br />
<br />
&nbsp; &nbsp; KlForCustTesterDataContract klForCustTesterDataContract;<br />
<span style="color: #000000;">&#125;</span></div></div>
<h3>2.1 Adding the override method</h3>
<p>We will first write the method that will override the modified of the checkbox control. Simply add a new method to the KlForCustTesterUIBuilder class:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">boolean</span> allowModifyDateModified<span style="color: #000000;">&#40;</span>FormCheckBoxControl _checkBoxControl<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// set enabled or disabled based on checkbox</span><br />
&nbsp; &nbsp; dialogFieldTransDate.<span style="color: #000000;">enabled</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">any2enum</span><span style="color: #000000;">&#40;</span>dialogFieldAllowModifyDate.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// or alternatively</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// dialogFieldTransDate.enabled(_checkBoxControl.checked());</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The code above sets the enabled method on the dialogFieldTransDate object based on the value property of dialogFieldAllowModifyDate object, or alternatively, the _checkBoxControl variable.<br />
As you may remember, we declared the DialogField variables in the class declaration. Of course we will still have to initialize these variables , and that&#8217;s what we&#8217;ll do when overriding the postBuild method. </p>
<h3>2.2 Overwriting the postBuild method</h3>
<p>Next, we need to override the postBuild method on our KlForCustTesterUIBuilder class. This method will be called after the dialog is created, so it is a good place to put our logic. </p>
<p>Override the method:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> postBuild<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Next, let&#8217;s add some code to this method, starting with the code that retrieves the data contract object, which is pretty easy:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> postBuild<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get datacontract</span><br />
&nbsp; &nbsp; klForCustTesterDataContract <span style="color: #00007f;">=</span> this.<span style="color: #000000;">dataContractObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Next, we retrieve the DialogField objects:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> postBuild<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get datacontract</span><br />
&nbsp; &nbsp; klForCustTesterDataContract <span style="color: #00007f;">=</span> this.<span style="color: #000000;">dataContractObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get dialog fields</span><br />
&nbsp; &nbsp; dialogFieldTransDate &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00007f;">=</span> this.<span style="color: #000000;">bindInfo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">getDialogField</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> parmTransDate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; dialogFieldAllowModifyDate &nbsp;<span style="color: #00007f;">=</span> this.<span style="color: #000000;">bindInfo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">getDialogField</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> parmAllowModifyDate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>In the code above, the <strong>bindInfo() </strong>method returns an object of type <strong>SysOperationUIBindInfo</strong>. This contains information about which dialog controls the data members are bound to. By providing a reference to the parmTransDate and parmAllowModifyDate member when calling the <strong>getDialogField()</strong> method, we get the dialog control that is associated with each member. </p>
<p>Next, we will register the method we want to override:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> postBuild<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get datacontract</span><br />
&nbsp; &nbsp; klForCustTesterDataContract <span style="color: #00007f;">=</span> this.<span style="color: #000000;">dataContractObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get dialog fields</span><br />
&nbsp; &nbsp; dialogFieldTransDate &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00007f;">=</span> this.<span style="color: #000000;">bindInfo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">getDialogField</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> parmTransDate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; dialogFieldAllowModifyDate &nbsp;<span style="color: #00007f;">=</span> this.<span style="color: #000000;">bindInfo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">getDialogField</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> parmAllowModifyDate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// register override methods</span><br />
&nbsp; &nbsp; dialogFieldAllowModifyDate.<span style="color: #000000;">registerOverrideMethod</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>FormCheckBoxControl<span style="color: #00007f;">,</span> modified<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterUIBuilder<span style="color: #00007f;">,</span> allowModifyDateModified<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> this<span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>As you can see, we can use the registerOverrideMethod() method to override methods on dialog. This is a huge improvement over overriding methods on dialogs in 2009. We simply point to the method we want to override (FormCheckBoxControl.modified) and the method the needs to be executed (KlForCustTesterUIBuilder.allowModifyDateModified). </p>
<p>Finally, we initialize the value of the enabled property, and the complete method will look like this:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> postBuild<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get datacontract</span><br />
&nbsp; &nbsp; klForCustTesterDataContract <span style="color: #00007f;">=</span> this.<span style="color: #000000;">dataContractObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// get dialog fields</span><br />
&nbsp; &nbsp; dialogFieldTransDate &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #00007f;">=</span> this.<span style="color: #000000;">bindInfo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">getDialogField</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> parmTransDate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; dialogFieldAllowModifyDate &nbsp;<span style="color: #00007f;">=</span> this.<span style="color: #000000;">bindInfo</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #000000;">getDialogField</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterDataContract<span style="color: #00007f;">,</span> parmAllowModifyDate<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// register override methods</span><br />
&nbsp; &nbsp; dialogFieldAllowModifyDate.<span style="color: #000000;">registerOverrideMethod</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>FormCheckBoxControl<span style="color: #00007f;">,</span> modified<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">methodstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterUIBuilder<span style="color: #00007f;">,</span> allowModifyDateModified<span style="color: #000000;">&#41;</span><span style="color: #00007f;">,</span> this<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// enable/disable transdate based on checkbox</span><br />
&nbsp; &nbsp; dialogFieldTransDate.<span style="color: #000000;">enabled</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">any2enum</span><span style="color: #000000;">&#40;</span>dialogFieldAllowModifyDate.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<h3>3. One more attribute</h3>
<p>Now, we&#8217;ve created the UIBuilder class, but we still have to link it to our data contract. That&#8217;s what the <strong>SysOperationContractProcessingAttribute </strong>attribute is for. </p>
<p>To link the UIBuilder class to the data contract, open the <strong>classDeclaration</strong> method of the <strong>KlForCustTesterDataContract</strong> class, and add the <strong>SysOperationContractProcessingAttribute</strong>:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataContractAttribute<span style="color: #00007f;">,</span><br />
&nbsp; &nbsp; SysOperationContractProcessingAttribute<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">classstr</span><span style="color: #000000;">&#40;</span>KlForCustTesterUIBuilder<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">class</span> KlForCustTesterDataContract<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp;name;<br />
&nbsp; &nbsp; TransDate &nbsp; transDate;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> &nbsp; &nbsp; &nbsp; &nbsp; packedQuery;<br />
<br />
&nbsp; &nbsp; NoYesId &nbsp; &nbsp; allowModifyDate;<br />
<span style="color: #000000;">&#125;</span></div></div>
<h3>4. Testing!</h3>
<p>But wait (you already know what I&#8217;m going to say right), first click the Generate Incremental CIL button to generate CIL.<br />
<img src="http://www.artofcreation.be/wp-content/uploads/generateCIL.png" alt="" title="generateCIL" width="634" height="99" class="aligncenter size-full wp-image-1229" /></p>
<p>Right click the KlForCustTesterServiceController menu item we created on day 2, and choose open. You should see this dialog:<br />
<img src="http://www.artofcreation.be/wp-content/uploads/CheckboxUnChecked.png" alt="" title="CheckboxUnChecked" width="620" height="320" class="aligncenter size-full wp-image-1371" /><br />
When you check the checkbox, you should see that the date field is enabled.<br />
<img src="http://www.artofcreation.be/wp-content/uploads/CheckboxChecked.png" alt="" title="CheckboxChecked" width="620" height="320" class="aligncenter size-full wp-image-1370" /></p>
<p><a href="http://www.artofcreation.be/wp-content/SharedProject_KlFor_SysOperation_Day3.xpo">Download the XPO for part 3 here</a>. </p>
<p>That concludes my blog posts about SysOperation, I hope you like it, and I&#8217;m looking forward to your feedback.<br />
Have fun making batches!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/08/24/ax2012-sysoperation-part-3-sysoperationautomaticuibuilder/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>AX2012: SysOperation part 2: SysOperationServiceController</title>
		<link>http://www.artofcreation.be/2011/08/23/ax2012-sysoperation-part-2-sysoperationservicecontroller/</link>
		<comments>http://www.artofcreation.be/2011/08/23/ax2012-sysoperation-part-2-sysoperationservicecontroller/#comments</comments>
		<pubDate>Tue, 23 Aug 2011 10:20:31 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[SysOperation]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1258</guid>
		<description><![CDATA[Hi again. In part 1, we created a nice batch using data contracts, service operation and the SysOperationServiceController class. Today, we will place our menu item on the Customers form, so we can process the customer that is selected in the grid. It will look like this: A thing that is still missing though, is [...]]]></description>
			<content:encoded><![CDATA[<p>Hi again. </p>
<p>In <a href="http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/">part 1</a>, we created a nice batch using data contracts, service operation and the SysOperationServiceController class. </p>
<p>Today, we will place our menu item on the Customers form, so we can process the customer that is selected in the grid. It will look like this:<br />
<img src="http://www.artofcreation.be/wp-content/uploads/Customers-form.png" alt="" title="Customers form" width="600" height="244" class="aligncenter size-full wp-image-1266" /><br />
A thing that is still missing though, is a way to work with the Args that are passed when a menu item is executed. We want to be able to set the query on our data contract before showing the batch dialog. We might also want to have a default value in some fields, for example, the date should be today&#8217;s date every time we launch the dialog.<br />
We can do all of that by extending the SysOperationServiceController class. </p>
<p>So let&#8217;s do that!</p>
<p>Create a new class that extends SysOperationServiceController</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">class</span> KlForCustTesterServiceController <span style="color: #0000ff;">extends</span> SysOperationServiceController<br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Now let&#8217;s create a method that constructs an instance of this class based on the Args object</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> KlForCustTesterServiceController newFromArgs<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KlForCustTesterServiceController &nbsp; &nbsp;klForCustTesterServiceController;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create a new instance of the controller</span><br />
&nbsp; &nbsp; klForCustTesterServiceController <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KlForCustTesterServiceController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// initialize from args</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// one of the things this will do is read the &quot;parameters&quot; property from the menu item </span><br />
&nbsp; &nbsp; klForCustTesterServiceController.<span style="color: #000000;">initializeFromArgs</span><span style="color: #000000;">&#40;</span>_args<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// return a new instance of this controller</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> klForCustTesterServiceController;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Above is the basic code that should be in your construct method. However, this doesn&#8217;t do anything more than the SysOperationServiceController already does, so let&#8217;s add the logic that sets the date to today&#8217;s date.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> KlForCustTesterServiceController newFromArgs<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KlForCustTesterServiceController &nbsp; &nbsp;klForCustTesterServiceController;<br />
&nbsp; &nbsp; klForCustTesterDataContract &nbsp; &nbsp; klForCustTesterDataContract<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create a new instance of the controller</span><br />
&nbsp; &nbsp; klForCustTesterServiceController <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KlForCustTesterServiceController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// initialize from args</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// one of the things this will do is read the &quot;parameters&quot; property from the menu item </span><br />
&nbsp; &nbsp; klForCustTesterServiceController.<span style="color: #000000;">initializeFromArgs</span><span style="color: #000000;">&#40;</span>_args<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// get datacontract</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// the string should be the same as the parameter name!</span><br />
&nbsp; &nbsp; klForCustTesterDataContract <span style="color: #00007f;">=</span> klForCustTesterServiceController.<span style="color: #000000;">getDataContractObject</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'_klForCustTesterDataContract'</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// default current date</span><br />
&nbsp; &nbsp; klForCustTesterDataContract.<span style="color: #000000;">parmTransDate</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">systemDateGet</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// return a new instance of this controller</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> klForCustTesterServiceController;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>As you can see, the Data Contract is fetched using the getDataContractObject() method. This will also unpack any values that were packed before, just like a normal RunBase would.<br />
Setting the date is a simple as setting the parm method on the data contract. </p>
<p>Now let&#8217;s add the logic that creates the correct query by adding a range based on the record in the Args variable.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> KlForCustTesterServiceController newFromArgs<span style="color: #000000;">&#40;</span>Args _args<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KlForCustTesterServiceController &nbsp; &nbsp;klForCustTesterServiceController;<br />
&nbsp; &nbsp; klForCustTesterDataContract &nbsp; &nbsp; &nbsp; &nbsp; klForCustTesterDataContract;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; CustTable &nbsp; custTable;<br />
&nbsp; &nbsp; Query &nbsp; &nbsp; &nbsp; query;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create a new instance of the controller</span><br />
&nbsp; &nbsp; klForCustTesterServiceController <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> KlForCustTesterServiceController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #007f00;">// initialize from args</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// one of the things this will do is read the &quot;parameters&quot; property from the menu item </span><br />
&nbsp; &nbsp; klForCustTesterServiceController.<span style="color: #000000;">initializeFromArgs</span><span style="color: #000000;">&#40;</span>_args<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// get datacontract</span><br />
&nbsp; &nbsp; <span style="color: #007f00;">// the string should be the same as the parameter name!</span><br />
&nbsp; &nbsp; klForCustTesterDataContract <span style="color: #00007f;">=</span> klForCustTesterServiceController.<span style="color: #000000;">getDataContractObject</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'_klForCustTesterDataContract'</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// default current date</span><br />
&nbsp; &nbsp; klForCustTesterDataContract.<span style="color: #000000;">parmTransDate</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff;">systemDateGet</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// check if the record is of type CustTable</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>_args <span style="color: #00007f;">&amp;&amp;</span> _args.<span style="color: #000000;">dataset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #00007f;">==</span> <span style="color: #0000ff;">tableNum</span><span style="color: #000000;">&#40;</span>CustTable<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// cast record</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; custTable <span style="color: #00007f;">=</span> _args.<span style="color: #000000;">record</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// create new query</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; query <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> query<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">queryStr</span><span style="color: #000000;">&#40;</span>KlForCustomers<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// add range</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; query.<span style="color: #000000;">dataSourceTable</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: #000000;">&#41;</span>.<span style="color: #000000;">addRange</span><span style="color: #000000;">&#40;</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: #000000;">&#41;</span>.<span style="color: #000000;">value</span><span style="color: #000000;">&#40;</span>queryValue<span style="color: #000000;">&#40;</span>custTable.<span style="color: #000000;">AccountNum</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// set query on datacontract</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; klForCustTesterDataContract.<span style="color: #000000;">setQuery</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// return a new instance of this controller</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> klForCustTesterServiceController;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>There you go. Now we need to make a main method that uses this construct method, and starts the operation:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <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><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; KlForCustTesterServiceController klForCustTesterServiceController;<br />
&nbsp; &nbsp; ;<br />
<br />
&nbsp; &nbsp; klForCustTesterServiceController <span style="color: #00007f;">=</span> KlForCustTesterServiceController<span style="color: #00007f;">::</span><span style="color: #000000;">newFromArgs</span><span style="color: #000000;">&#40;</span>_args<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; klForCustTesterServiceController.<span style="color: #000000;">startOperation</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>We also need to create a new menu item. Right click you project &#8211; New &#8211; Menu Item.<br />
Enter the following properties:</p>
<p><strong>ObjectType</strong>: Class<br />
<strong>Object</strong>: KlForCustTesterServiceController<br />
<strong>Parameters</strong>: KlForCustTesterDataService.testCustomer</p>
<p>Next, add the menu item to the CustTable form:<br />
<img src="http://www.artofcreation.be/wp-content/uploads/custtablebutton.png" alt="" title="Custtable button" width="542" height="408" class="aligncenter size-full wp-image-1265" /></p>
<p>Finally before testing, click the Generate Incremental CIL button to generate CIL.<br />
<img src="http://www.artofcreation.be/wp-content/uploads/generateCIL.png" alt="" title="generateCIL" width="634" height="99" class="aligncenter size-full wp-image-1229" /></p>
<p>Right click the CustTable form and click Open. This will open the Customers form. Switch to the grid view (Ctrl + Shift + G), and select a record. Then click the button we just added.<br />
<a href="http://www.artofcreation.be/wp-content/uploads/Customers-form.png"><img src="http://www.artofcreation.be/wp-content/uploads/Customers-form.png" alt="" title="Customers form" width="600" height="244" class="aligncenter size-full wp-image-1266" /></a></p>
<blockquote><p>Note: a bug (or something I do wrong?) I found is that the query values that are displayed on the dialog seem to be &#8220;lagging&#8221;. The wrong values are shown, but when you click ok, the correct values are used, unless you click the select button.<br />
This can be fixed by adding this line before returning the controller object:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">KlForCustTesterServiceController.<span style="color: #000000;">queryChanged</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;_klForCustTesterDataContract.parmQuery&quot;</span><span style="color: #00007f;">,</span> query<span style="color: #000000;">&#41;</span>;</div></div>
<p>This is probably not a nice way to do this, so I&#8217;ll look into it, and let you know.
</p></blockquote>
<p>When you click Ok on the dialog, you should see that only the customer you&#8217;ve selected will be processed. You will also see that the date has been set to today&#8217;s date, just like we wanted. </p>
<p><a href="http://www.artofcreation.be/wp-content/SharedProject_KlFor_SysOperation_Day2.xpo">Download the XPO for part 2 here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/08/23/ax2012-sysoperation-part-2-sysoperationservicecontroller/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AX2012: SysOperation part 1: Data Contracts and Service Operations</title>
		<link>http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/</link>
		<comments>http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 11:00:11 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[SysOperation]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1196</guid>
		<description><![CDATA[Hi All :-) This is part 1 of a series of 3 blog posts where I demonstrate how to create batch classes using the SysOperation classes (Read the introduction here) We are going to create a batch that looks like this: And we are going to do that without creating a RunBaseBatch class! Note: Just [...]]]></description>
			<content:encoded><![CDATA[<p>Hi All :-) </p>
<p>This is part 1 of a series of 3 blog posts where I demonstrate how to create batch classes using the SysOperation classes (Read the <a href="http://www.artofcreation.be/2011/08/21/ax2012-sysoperation-introduction/">introduction here</a>)</p>
<p>We are going to create a batch that looks like this:<br />
<img src="http://www.artofcreation.be/wp-content/uploads/BOFBatch.png" alt="" title="Batch screenshot" width="625" height="347" class="aligncenter size-full wp-image-1232" /><br />
And we are going to do that without creating a RunBaseBatch class!</p>
<blockquote><p>Note: Just to be clear: the batch class won&#8217;t actually do anything useful, everything is just for demo purposes. </p></blockquote>
<p>Okay, let&#8217;s start!</p>
<h3>1. Data Contract</h3>
<p>First, we will create a data contract. The data contract contains data members that represent the fields that will be available on the dialog. </p>
<p>Let&#8217;s create a new class, KlForCustTesterDataContract:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataContractAttribute<span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">class</span> KlForCustTesterDataContract<br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The string DataContractAttribute indicates that this class is a Data Contract. The square brackets [] indicate that this string is an attribute (You can read more about attributes on <a href="http://msdn.microsoft.com/en-us/library/gg846588.aspx">MSDN</a>). </p>
<p>Next, let&#8217;s add Data Members to this contract by first declaring them in the class declaration</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataContractAttribute<span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">class</span> KlForCustTesterDataContract<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp;name;<br />
&nbsp; &nbsp; TransDate &nbsp; transDate;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">str</span> &nbsp; &nbsp; &nbsp; &nbsp; packedQuery;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>We add a string field, a date field, and a query. We still need to create parm methods for these variables. </p>
<p>This is just a simple string field, nothing special here except for the DataMemberAttribute attribute that indicates that this method is da data member.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataMemberAttribute<span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">public</span> Name parmName<span style="color: #000000;">&#40;</span>Name _name <span style="color: #00007f;">=</span> name<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; name <span style="color: #00007f;">=</span> _name;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> name;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>The date field is of type TransDate, so we&#8217;ll give it a nicer label by using the SysOperationLabelAttribute attribute to specify the label used.<br />
Also note that, when two attributes are specified, the are separated by a comma (,).</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataMemberAttribute<br />
<span style="color: #00007f;">,</span>SysOperationLabelAttribute<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">literalStr</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;@SYS11284&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span> <span style="color: #007f00;">// today's date</span><br />
<span style="color: #0000ff;">public</span> TransDate parmTransDate<span style="color: #000000;">&#40;</span>TransDate _transDate <span style="color: #00007f;">=</span> transDate<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; transDate <span style="color: #00007f;">=</span> _transDate;<br />
<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> transDate;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>We will also add a query, so we can loop all customers. As you can see, we can specify the query by using the AifQueryTypeAttribute. The query KlForCustomers is just a query in the AOT with CustTable as a datasource (see xpo file at the end).</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>DataMemberAttribute<span style="color: #00007f;">,</span><br />
&nbsp; &nbsp; AifQueryTypeAttribute<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">'_packedQuery'</span><span style="color: #00007f;">,</span> <span style="color: #0000ff;">querystr</span><span style="color: #000000;">&#40;</span>KlForCustomers<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">str</span> parmQuery<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">str</span> _packedQuery <span style="color: #00007f;">=</span> packedQuery<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; packedQuery <span style="color: #00007f;">=</span> _packedQuery;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> packedQuery;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Next, we add two helper methods that are not Data Members, so we can easily set and get the query variable. </p>
<p>To get the query:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> Query getQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">new</span> Query<span style="color: #000000;">&#40;</span>SysOperationHelper<span style="color: #00007f;">::</span><span style="color: #000000;">base64Decode</span><span style="color: #000000;">&#40;</span>packedQuery<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>To set the query:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> setQuery<span style="color: #000000;">&#40;</span>Query _query<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; packedQuery <span style="color: #00007f;">=</span> SysOperationHelper<span style="color: #00007f;">::</span><span style="color: #000000;">base64Encode</span><span style="color: #000000;">&#40;</span>_query.<span style="color: #000000;">pack</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span></div></div>
<h3>2. Service class and operation</h3>
<p>Next, let&#8217;s create a service class called KlForCustTesterDataService.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000ff;">class</span> KlForCustTesterDataService<br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Right click the class, click properties, and set the run on property to server. </p>
<p>Adding a service operation to this service class is as simple as adding a method. As you can see, the SysEntryPointAttribute attribute indicates that this is a service operation, and our data contract is used as an argument.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>SysEntryPointAttribute<span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> testCustomer<span style="color: #000000;">&#40;</span>KlForCustomerTesterDataContract _klForCustomerTesterDataContract<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Of course, this method needs some demo functionality, so let&#8217;s add that:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#91;</span>SysEntryPointAttribute<span style="color: #000000;">&#93;</span><br />
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> testCustomer<span style="color: #000000;">&#40;</span>KlForCustTesterDataContract _klForCustTesterDataContract<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; QueryRun &nbsp; &nbsp;queryRun;<br />
&nbsp; &nbsp; CustTable &nbsp; custTable;<br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// info the name parameter</span><br />
&nbsp; &nbsp; info<span style="color: #000000;">&#40;</span>_klForCustTesterDataContract.<span style="color: #000000;">parmName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// create a new queryrun object</span><br />
&nbsp; &nbsp; queryRun <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> queryRun<span style="color: #000000;">&#40;</span>_klForCustTesterDataContract.<span style="color: #000000;">getQuery</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #007f00;">// loop all results from the query</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #000000;">&#40;</span>queryRun.<span style="color: #0000ff;">next</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; custTable <span style="color: #00007f;">=</span> queryRun.<span style="color: #000000;">get</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: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// display the accountnum</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; info<span style="color: #000000;">&#40;</span>custTable.<span style="color: #000000;">AccountNum</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<h3>3. Service</h3>
<p>Right click your project, and choose <strong>New </strong>- <strong>Service</strong>. Give this service the same name as the service class, KlForCustTesterDataService.<br />
In the properties of this node, set the <strong>class </strong>property to KlForCustTesterDataService<br />
Expand the node of your service, then right click on the <strong>Operations</strong> node.<br />
Click <strong>Add operation</strong> and check the <strong>add</strong> checkbox next to the method we&#8217;ve created, and click <strong>OK</strong>.</p>
<h3>4. Menu item</h3>
<p>All we need to do now is create a menu item so we can start our dialog.<br />
Do this by right clicking your project &#8211; <strong>New </strong>- <strong>Menu item</strong>. Name it KlForCustTesterDataService. </p>
<p>Enter the following properties:<br />
<strong>ObjectType</strong>: Class<br />
<strong>Object</strong>: SysOperationServiceController<br />
<strong>Parameters</strong>: KlForCustTesterDataService.testCustomer</p>
<p>As you can see, we don&#8217;t link directly to our service class, in stead, the class SysOperationServiceController will be used, and will know what service operation to start because it is specified in the <strong>parameters</strong> property. More about these controller class in part 2 of this series. </p>
<h3>5. Run it!</h3>
<p>But wait, we still have to do one small thing: compile our X++ into the common intermediate language (CIL). Don&#8217;t worry, it&#8217;s easy. Just click the Generate Incremental CIL button in the toolbar (this might take a while).<br />
<img src="http://www.artofcreation.be/wp-content/uploads/generateCIL.png" alt="" title="generateCIL" width="634" height="99" class="aligncenter size-full wp-image-1229" /></p>
<p>After CIL was generated, right click the menu item and click <strong>Open</strong>. You should see your batch class. As you can see, all fields from the datacontract are displayed, and a select button was automatically generated so you can modify the query.<br />
<img src="http://www.artofcreation.be/wp-content/uploads/BOFBatchFinished.png" alt="" title="BOF Batch Example" width="613" height="337" class="aligncenter size-full wp-image-1236" /><br />
Output when run in batch:<br />
<img src="http://www.artofcreation.be/wp-content/uploads/BatchOutput.png" alt="" title="Batch Output" width="631" height="334" class="aligncenter size-full wp-image-1238" /></p>
<p>In part 2, we will take a closer look at the SysOperationServiceController class. See you tomorrow. </p>
<p><a href="http://www.artofcreation.be/wp-content/SharedProject_KlFor_SysOperation_Day1.xpo">Download the XPO for part 1 here</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>AX2012: SysOperation introduction</title>
		<link>http://www.artofcreation.be/2011/08/21/ax2012-sysoperation-introduction/</link>
		<comments>http://www.artofcreation.be/2011/08/21/ax2012-sysoperation-introduction/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 16:28:01 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[2012]]></category>
		<category><![CDATA[Batch]]></category>
		<category><![CDATA[SysOperation]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1188</guid>
		<description><![CDATA[Hi everyone! Dynamics AX 2012 introduces a new way for creating batches, without using the RunBaseBatch class. The SysOperation* classes are part of the Business Operation Framework, and can be used to create these batches. Some documentation is already available on MSDN about the BOF and the SysOpertation classes, but I was still confused when [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everyone!</p>
<p>Dynamics AX 2012 introduces a new way for creating batches, without using the RunBaseBatch class. The SysOperation* classes are part of the Business Operation Framework, and can be used to create these batches.<br />
<img src="http://www.artofcreation.be/wp-content/uploads/clickitax2012.png" alt="" title="What you would like to do now" width="146" height="169" class="aligncenter size-full wp-image-1246" /><br />
Some documentation is already available on MSDN about the BOF and the SysOpertation classes, but I was still confused when creating such a batch class. That is why in the next 3 days, I will cover the basics on how to create these batches, so you don&#8217;t have to figure it all out on your own. </p>
<p>I hope to get some feedback too, because not everything is crystal clear to me either :-). </p>
<p>But anyway, this is what you can expect in the next 3 days:</p>
<p><strong>Day 1</strong> <a href="http://www.artofcreation.be/2011/08/22/ax2012-sysoperation-part-1-data-contracts-and-service-operations/">(link)</a><br />
A demonstration on how to create <strong>Data Contract</strong> classes and <strong>Service Operations</strong>. You will also learn how to use <strong>attributes</strong> like DataContractAttribute and DataMemberAttribute, and at the end, we will already have a working batch class. </p>
<p><strong>Day 2</strong> <a href="http://www.artofcreation.be/2011/08/23/ax2012-sysoperation-part-2-sysoperationservicecontroller/">(link)</a><br />
We will take a closer look at the <strong>SysOperationServiceController</strong> class, and will be creating our own controller. This will allow us to set properties on our Data Contract based on Args. This is useful when you batch is started by a button on a form that is linked to a datasource. </p>
<p><strong>Day 3</strong> <a href="http://www.artofcreation.be/2011/08/24/ax2012-sysoperation-part-3-sysoperationautomaticuibuilder/">(link)</a><br />
To make a fully functional batch, we need to be able to overwrite methods on our dialog field like lookup and modified. We also want to be able to change the properties of these fields, like enabling or disabling them. That&#8217;s just what the <strong>SysOperationAutomaticUIBuilder </strong>class is for, and we&#8217;ll look into that. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/08/21/ax2012-sysoperation-introduction/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Top reasons to follow best practices</title>
		<link>http://www.artofcreation.be/2011/08/16/top-reasons-follow-best-practices/</link>
		<comments>http://www.artofcreation.be/2011/08/16/top-reasons-follow-best-practices/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 17:14:16 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Best practices]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1067</guid>
		<description><![CDATA[Hi all. Here&#8217;s a list of af few reasons why I think it is important to fix those best practice errors :-). Improved performance Many best practices have an influence on performance. For example, it is best practice to set the property CreateRecIdIndex to True on tables with Created/Modified DateTime fields. If you don&#8217;t, this [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all. </p>
<p>Here&#8217;s a list of af few reasons why I think it is important to fix those best practice errors :-). </p>
<p><strong>Improved performance</strong><br />
Many best practices have an influence on performance. For example, it is best practice to set the property CreateRecIdIndex to True on tables with Created/Modified DateTime fields. If you don&#8217;t, this will have an adverse effect on the performance of those tables.<br />
Another example is that if you adhere to the best practices concerning the construction of classes and the use of batch classes, it will be much easier to improve performance by enabling batch multi-threading. </p>
<p><strong>Improved readability of code</strong><br />
When all developers follow best practices about formatting of code, the code will be more readable and easier to understand. Avoiding dead code and removing unused variables will also make the code less confusing. </p>
<p><strong>Developers learn</strong><br />
There are a lot of handy things you can learn by solving best practice deviations. Adding fields to field groups for example is a great way to avoid customizations to forms. And by figuring out what configuration is needed on a menu item, you learn about what effect configuration keys have on you solution. </p>
<p><strong>Improved security </strong><br />
Adding security and configuration keys is vital to good security. When ignoring best practices, an unauthorized user might cause a big mess that you&#8217;ll have to clean up. </p>
<p><strong>Certified for Dynamics AX</strong><br />
Making sure your solution is best practice deviation free goes a long way towards passing the <a href="http://en-us.lionbridge.com/ProductEngg.aspx?pageid=1197&#038;LangType=1033">Software Solution Test</a>. </p>
<p><strong>Better user experience</strong><br />
Some best practices have to do with labels, help texts, descriptions for batch task, etc. If you ignore those, it will be more difficult for the user to understand the solution you created. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/08/16/top-reasons-follow-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Try Catch and transactions</title>
		<link>http://www.artofcreation.be/2011/08/10/try-catch-and-transactions/</link>
		<comments>http://www.artofcreation.be/2011/08/10/try-catch-and-transactions/#comments</comments>
		<pubDate>Wed, 10 Aug 2011 10:57:53 +0000</pubDate>
		<dc:creator>Klaas Deforche</dc:creator>
				<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[Exceptions]]></category>
		<category><![CDATA[Try Catch]]></category>

		<guid isPermaLink="false">http://www.artofcreation.be/?p=1151</guid>
		<description><![CDATA[Hi all, Exception handling can be quite confusing in Dynamics AX, so I wanted to share some quick facts about try/catch and transactions. The general rule is that exceptions are caught in the outer most catch, where the ttslevel is 0. This means that if you put a transaction around a try/catch, your exceptions will [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>Exception handling can be quite confusing in Dynamics AX, so I wanted to share some quick facts about try/catch and transactions. </p>
<p>The general rule is that exceptions are caught in the outer most catch, where the ttslevel is 0. This means that if you put a transaction around a try/catch, your exceptions will not be caught.<br />
The following two jobs demonstrate that:</p>
<p>Transaction inside try/catch:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0000ff;">try</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">ttsBegin</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">throw</span> error<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;an error&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">ttsCommit</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; catch<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;error caught&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></div>
<p>Output: </p>
<blockquote><p>Error	an error<br />
Info	error caught</p></blockquote>
<p>Try/catch inside transaction:</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #0000ff;">ttsBegin</span>;<br />
&nbsp; &nbsp; <span style="color: #0000ff;">try</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">throw</span> error<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;an error&quot;</span><span style="color: #000000;">&#41;</span>; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; catch<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; info<span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;error caught&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">ttsCommit</span>;</div></div>
<p>Output:</p>
<blockquote><p>Error	an error</p></blockquote>
<p>As you can see, the error is not caught when the transaction is around the try catch. </p>
<p>However, there are two exceptions to this rule.<br />
The following code demonstrates that UpdateConflict and DupplicateKeyException can be caught inside a transaction.</p>
<div class="codecolorer-container xpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="xpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; Set &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set <span style="color: #00007f;">=</span> <span style="color: #0000ff;">new</span> Set<span style="color: #000000;">&#40;</span>Types<span style="color: #00007f;">::</span><span style="color: #000000;">Enum</span><span style="color: #000000;">&#41;</span>; <span style="color: #007f00;">// a set containing all possible exceptions</span><br />
&nbsp; &nbsp; SetEnumerator &nbsp; se; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// enumerator used to loop though the set with exception</span><br />
&nbsp; &nbsp; Exception &nbsp; &nbsp; &nbsp; exception; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #007f00;">// used to cast the value from the set</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">boolean</span> &nbsp; &nbsp; &nbsp; &nbsp; caughtInside;<br />
&nbsp; &nbsp; ;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// add all exception to a set</span><br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #0000ff;">Break</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">CLRError</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">CodeAccessSecurity</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">DDEerror</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Deadlock</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">DuplicateKeyException</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">DuplicateKeyExceptionNotRecovered</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Error</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Info</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Internal</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Numeric</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">PassClrObjectAcrossTiers</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Sequence</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Timeout</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">UpdateConflict</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">UpdateConflictNotRecovered</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; set.<span style="color: #000000;">add</span><span style="color: #000000;">&#40;</span>Exception<span style="color: #00007f;">::</span><span style="color: #000000;">Warning</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// create enumerator</span><br />
&nbsp; &nbsp; se <span style="color: #00007f;">=</span> set.<span style="color: #000000;">getEnumerator</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #007f00;">// loop all exceptions</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">while</span><span style="color: #000000;">&#40;</span>se.<span style="color: #000000;">moveNext</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// set flag false</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; caughtInside <span style="color: #00007f;">=</span> <span style="color: #0000ff;">false</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// begin outer try catch</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">ttsBegin</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// begin inner try catch</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">try</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// cast exception</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; exception <span style="color: #00007f;">=</span> se.<span style="color: #000000;">current</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// trhow exception</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">throw</span> exception;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; catch<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// set flag to indicate the exception was caught inside the transaction</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; caughtInside <span style="color: #00007f;">=</span> <span style="color: #0000ff;">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; warning<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strFmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;%1 can be caught inside transaction&quot;</span><span style="color: #00007f;">,</span> exception<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// throw exception again to catch it outside of transaction</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">throw</span> exception;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">ttsCommit</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; catch<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007f00;">// for once, it's ok to catch everyting :) &nbsp; </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">if</span><span style="color: #000000;">&#40;</span>caughtInside<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; warning<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">strFmt</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">&quot;%1 can alse be caught outside of the transaction&quot;</span><span style="color: #00007f;">,</span> exception<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 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 can only be caught outside of the transaction&quot;</span><span style="color: #00007f;">,</span> exception<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></div>
<p>Output:</p>
<blockquote><p>Info	Info can only be caught outside of the transaction<br />
Info	Warning can only be caught outside of the transaction<br />
Info	Deadlock can only be caught outside of the transaction<br />
Info	Error can only be caught outside of the transaction<br />
Info	Internal can only be caught outside of the transaction<br />
Info	Break can only be caught outside of the transaction<br />
Info	DDEerror can only be caught outside of the transaction<br />
Info	Sequence can only be caught outside of the transaction<br />
Info	Numeric can only be caught outside of the transaction<br />
Info	CLRError can only be caught outside of the transaction<br />
Info	CodeAccessSecurity can only be caught outside of the transaction<br />
<strong>Warning	UpdateConflict can be caught inside transaction<br />
Warning	UpdateConflict can alse be caught outside of the transaction</strong><br />
Info	UpdateConflictNotRecovered can only be caught outside of the transaction<br />
<strong>Warning	DuplicateKeyException can be caught inside transaction<br />
Warning	DuplicateKeyException can alse be caught outside of the transaction</strong><br />
Info	DuplicateKeyExceptionNotRecovered can only be caught outside of the transaction<br />
Info	Timeout can only be caught outside of the transaction<br />
Info	PassClrObjectAcrossTiers can only be caught outside of the transaction
</p></blockquote>
<p>It is also noteworthy that, when you enter a catch block, there has been a implicit ttsabort, so the transaction has been rolled back. However this is not true for UpdateConflict and DuplicateKeyException when they were caught inside a transaction. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.artofcreation.be/2011/08/10/try-catch-and-transactions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

