Map, set, etc., should not be passed as parameter to a static method

LCS BP error: Map, set, etc., should not be passed as parameter to a static method

 

Developer normally used Map or Set to pass as argument to the static method. Which is not recommended by LCS.

Solution:

Here is the way to convert the SET or MAP to container to fix this BP warnings.

Convert SET to Container and vice versa:

In this example I have taken Worktable as example for demonstrating.

Container                   set2Con;

SetEnumerator          se;

whsworktable            worktable;

Set                            container2Set; //SET Class

Set                            setWorkHeaders = new Set (Types::Record);

//Add the marked records of worktable using for…Loop into set.

setWorkHeaders.add(worktable);

//Pack the set value into container

set2Con = setWorkHeaders.pack();

Pass this container as argument to the static method. In Static method using the Set

class, convert the CONTAINER into SET again.

container2Set = Set::create (set2Con);

Using SET enumerator, read the value from set

se = container2Set.getEnumerator();

while (se.moveNext())

{

workTable = se.current();

info(strFmt(“%1”,worktable.workId));

}

}

 

 

Convert from MAP to Container and vice versa:

Container                   map2Container;

MapIterator                mi;

whsworktable            worktable;

Map                           container2Map; //MAP Class

Map                          itemAttribMap = new Map (Types::String, Types::String);

 

//Add the Attribute name and attribute Values from attribute into MAP.

while select productAttribValues order by Name,value

where productAttribValues.ProductId == it.Product

{

itemAttribMap.insert(productAttribValues.Name,productAttribValues.Value);

}

//Pack the Map value into container

map2Container = itemAttribMap.pack();

Pass this container as argument to the static method. In Static method using the MAP class convert the

CONTAINER into Map again.

container2Map = Map::create(map2Container);

Using Map iterator, read the value from Map

mi = container2Map.getEnumerator();

while (mi.moveNext())

{

info(strFmt(“Key = %1, Value = %2”,mi.key(), mi.value()));

mi.next()

}

}

Advertisements

About Siva Kumar

I am 13+ years of experience in Information technology and 11+ years of experiance in MBS Dynamics AX practise.
This entry was posted in AX 2012. Bookmark the permalink.

One Response to Map, set, etc., should not be passed as parameter to a static method

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s