<?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>Johan Mulder dot com &#187; Dynamics AX</title>
	<atom:link href="https://johanmulder.com/?feed=rss2&#038;tag=dynamics-ax" rel="self" type="application/rss+xml" />
	<link>https://johanmulder.com</link>
	<description>Blogging about IT and stuff</description>
	<lastBuildDate>Mon, 19 Jan 2015 15:45:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.39</generator>
	<item>
		<title>AX Deleting items from a map</title>
		<link>https://johanmulder.com/?p=33</link>
		<comments>https://johanmulder.com/?p=33#comments</comments>
		<pubDate>Tue, 05 Aug 2014 16:16:45 +0000</pubDate>
		<dc:creator><![CDATA[johanmulder]]></dc:creator>
				<category><![CDATA[Dynamics AX Development]]></category>
		<category><![CDATA[AX 2009]]></category>
		<category><![CDATA[AX 2012]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Dynamics AX]]></category>
		<category><![CDATA[iterator]]></category>
		<category><![CDATA[X++]]></category>

		<guid isPermaLink="false">http://johanmulder.com/?p=33</guid>
		<description><![CDATA[I faced a challenge in deleting specific items from a map today. The problem occurs when the recordIterator.delete() x++ statement is executed. Any consecutive statement using the recordIterator variable will throw the exception &#8216;the iterator does not designate a valid element&#8217;. According to SysDictCoder it is not a problem to remove items using the ListIterator &#8230; <a href="https://johanmulder.com/?p=33" class="more-link">Continue reading <span class="screen-reader-text">AX Deleting items from a map</span></a>]]></description>
				<content:encoded><![CDATA[<p>I faced a challenge in deleting specific items from a map today. The problem occurs when the recordIterator.delete() x++ statement is executed. Any consecutive statement using the recordIterator variable will throw the exception &#8216;the iterator does not designate a valid element&#8217;. According to <a href="http://sysdictcoder.com/deleting-items-from-a-list/" title="SysDictCoder" target="_blank">SysDictCoder</a> it is not a problem to remove items using the ListIterator though.</p>
<p>The solutions lays within the use of a set in which the keys of the items that needs to be deleted are stored. After the first iteration another iteration takes place to actually delete the applicable items from the map.</p>
<pre class="brush:cpp">
public Map cleanupRecordMap(Map _recordMap)
{
    MapIterator     recordIterator = new MapIterator(_recordMap);
    Set             deleteRecordSet = new Set(Types::String);
    SetEnumerator   deleteRecordSetEnumerator;
    ;

    if(_recordMap.elements() > 0)
    {
        while(recordIterator.more())
        {
            if(true)
            {
                // mark record to be deleted by adding it to a set
                deleteRecordSet.add(recordIterator.domainValue());
            }
            
            recordIterator.next();                                 
        }
                
        // use the set of keys to remove them from the map
        deleteRecordSetEnumerator = deleteRecordSet.getEnumerator();
        while(deleteRecordSetEnumerator.moveNext())
        {
            _recordMap.remove(deleteRecordSetEnumerator.current());   
        }
    }       

    return _recordMap;
}

</pre>
]]></content:encoded>
			<wfw:commentRss>https://johanmulder.com/?feed=rss2&#038;p=33</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
