Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Monday, July 31, 2006

Map & MapEnumerator Objects

Something that I find myself using a lot in code is Map and MapEnumerator objects. Back when I first started in Ax we use to store values in tempTables. This still has it's place, but it's more over head than using a Map. A Map, or several of them, can be used as a temp data store for the given scope of a process. This takes us less over head, and is much quicker than a Temp. Table.

I have used maps in different locations, but the point of a map is to store whatever values you need to, and at a given point act on those values. Below are two code examples. The first is an example of how to create a map, and insert values into it:

Map Example:

Map m;
;

m = new Map(Types::Integer,Types::Integer);

MarkMap.insert(InventTable.RecId,_markSKUs);
MarkMap.valueSet();

Below here is code for taking a known key value and lookup the corresponding value assoicated with the given key:

MarkMap.exists(InventTable.RecId)
MarkMap.lookup(InventTable.RecId)

This is a wonderful way to look up the value because you have the exact key. What if you wanted to transverse or enumrate through a given map to act on each value. This would be similar to moving through a resultset, etc:

MapEnumerator ME;
;

ME = new MapEnumerator(MarkMap);
while(ME.moveNext())
{
// .. preform some logic ..
}

With this you can now walk through or enumrate through a given map and act upon each value stored in it. Like I said, Maps are very cool, easy to use, and much faster and preferred than using a temp table. Check back soon for more posting on code examples, how to's, etc.

Find a job at: www.DynamicsAXJobs.com

4 Comments:

Anonymous Anonymous said...

Speaking of maps. What are their limits speaking of no of entries? total space in map?

7:29 PM  
Anonymous Anonymous said...

As you are waiting with RecId's in your example, you should be carefule with using Integer as Type ... changed since version 4 :-)
One approach I use is the following:
DictType dt = new DictType(extendedTypeNum(recid));
map = new Map(dt.baseType(),Types::Integer);

br Karsten

8:12 AM  
Blogger Alex Kwitny (Kwitwell.com) said...

I think you are calling a needless line. MarkMap.valueSet() returns a set. You aren't doing anything with it, so it is misleading.

Unless I'm misunderstanding the purpose of your code.

http://msdn.microsoft.com/en-us/library/aa591362.aspx

3:59 PM  
Blogger brandon said...

Alex you are correct actually that line of code is not needed.

8:51 PM  

Post a Comment

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved