web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

How to add List to a container

(0) ShareShare
ReportReport
Posted on by 6,480

Hello,

Is there possibility to add a List into a container?

I tried with myList.pack(). It is compiled without errors, but when I run the code, I get the error message that it does not have a pack method.

myList is comes from a contract class that I pass to my method. So there is a parm method in contract class which returns the List and that is what I assign to myList List.

Thanks.

I have the same question (0)
  • Suggested answer
    huijij Profile Picture
    19,811 on at

    Hi Johnny,

    Please refer to the usage of the List.pack Method:

    docs.microsoft.com/.../microsoft.dynamics.ax.xpp.list.pack

  • Martin Dráb Profile Picture
    239,031 Most Valuable Professional on at

    You can't add object references to a container, you indeed need to pack the list to a container and then you can add this container to another container, if required.

    Can you show us your code, please?

  • Johnny Profile Picture
    6,480 on at

    Hi Martin,

    here is the part of code:

    List localParmTableFieldList = localParmTableRecord.parmTableFieldList();
    List localList = new List(Types::Class);
    localList.addEnd(localParmTableRecord.parmTableFieldList());
    
    ListIterator localParmTableFieldListIterator = new ListIterator(localParmTableFieldList);
    
    container c;
    c = conIns(c, conCounter, _localTableData.parmTableName());
    
    
    
    while (localParmTableFieldListIterator.more())
    {
        conCounter  ;
        Dynamics.AX.Application.XXXParmTableField localParmTableField = localParmTableFieldListIterator.value(); //I use Dynamics.AX.Application here because there is a .NET class with same name and compiler needs to know which to reference
        
        c = conIns(c, conCounter, localList.pack()); //Error is thrown here after running the code, not during the compilation
    
        
    
        localParmTableFieldListIterator.next();
    }

    So, I assign List returned from a contract class to the Local List variable and use the "pack" of it. Then I built the code without errors, but the error is thrown during the execution.

    Here is the parm method from the contract class I use:

    The error message is "XXXParmTableField object does not have method 'Pack'"

    [
        DataMemberAttribute("XXXParmTableField"),
        DataCollection(Types::Class, classStr(XXXParmTableField)),
        AifCollectionTypeAttribute('_tableFieldList', Types::Class, classStr(XXXParmTableField)),
        AifCollectionTypeAttribute('return', Types::Class, classStr(XXXParmTableField))
    ]
    public List parmTableFieldList(List _tableFieldList = tableFieldList)
    {
        if (!prmIsDefault(_tableFieldList))
        {
            tableFieldList = _tableFieldList;
        }
    
        return tableFieldList;
    }

  • Martin Dráb Profile Picture
    239,031 Most Valuable Professional on at

    You can't add object references to a container. That's exactly what you're trying to do and that's the reason why your code fails.

    But it's not about the List - it's about XXXParmTableField objects. The error message tells you that.

    You can't put XXXParmTableField objects to a container - as with the list, the solution is packing the internal state to a container. It seems that packing a list is able to pack the contents as well, as long as the elements are packable (have pack() method). Therefore let XXXParmTableField implement SysPackable interface.

    But first, what is the purpose of the container? Is it the right thing to do?

  • Johnny Profile Picture
    6,480 on at

    Thank you.

    Yes, I have to think maybe to use different approach.

    This is again about the comparison of table records between two different environments.

    Maybe Set is better.

    I should have Table records as "Field Name / Field Value" and a hash value generated by this value and later compare those between 2 environments

  • Martin Dráb Profile Picture
    239,031 Most Valuable Professional on at

    The approach isn't clear to me. You're saying that you "I should have Table records" but you're trying to create a container instead.

    Also, one of your previous thread was about a custom service. Why don't you simply use data contract objects and return the root object, leaving the serialization to F&O? Why are you trying to create a container in your code?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 659

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 465 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 304 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans