How To Pass a container via args.parm() functionality

Description:-
 
In AX 2012 (and previous versions), there is something called an args() which is short for arguments. It primarily comes into play where an object (like a form) opens up another object.

"The Args class is used to pass arguments such as a name, a caller, and parameters between application objects."

For example, if a form opens up from another form (think ListPage form to non-list page), information about that first form can be passed to the second form that is being opened. Usually this is data like what form the second form is being opened from, any special data parameters, etc.

Anyways, with that prefacing out of the way... 

NOTE: Italics below indicate an update to the original post. I think it will make more sense to what the post is showing.

The Problem: There is a requirement to pass a container from one form to another form and we cannot use args.parmObject() functionality as its already taken. For this example, we are trying to pass a set of record Ids. While containers can have other values, we're just going to use recIds so I can show a few other features.

The Issue: There is no way to pass a container through other meansThere are options to pass a string, enum, record set, static string value, or object instance, but no container. The parmObject instance is unavailable but args.parm() which only takes a string and is available.

The Resolution: Here is how it was solved:

  1. Take the container and convert it a string with commas separating the variables
  2. Pass the string to the args().parm() call in the first object
  3. Retrieve the string from args().parm() in the second object
  4. Convert the string to a container
For point 1, we need to use the con2str function. con2str(container c [, str sep] ).  For example, "con2Str(conRecIds,',')" would convert the container into a string using a comma as a separator.

For point 4, we need to use the str2con function. str2con(str_value [, str 10 _sep, boolean _convertNumericToInt64] ).  For an example, "str2con(strRecIds, ',', true)" would convert a string with commas as what distinguishes the individual components. The third parameter '_convertNumericToInt64' is really handy. It will take the string values and auto-convert them to an int64 (e.g. recId) when set to true.

Some code example: 

IN FORM 1:
[Action: Highlighted a few records and clicked a button] 


container conRecIds;
str       strRecIds;
tmpTable = dataSource_DS.getFirst(1);
while (tmpTable.RecId != 0)
{
   conRecIds += int642str(tmpTable.omRecID);
   tmpTable = dataSource_DS.getNext();
}
strRecIds = con2Str(conRecIds, ',');
element.args().parm(strRecIds);

IN FORM 2:

container conRecIds;
str       strRecIds;
strRecIds = args.parm();
conRecIds = str2con(strRecIds, ',', true);

Related Posts

Previous
Next Post »

Thanks for comments.....