web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,470

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
    RE: How to add List to a container

    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
    236,336 Most Valuable Professional on at
    RE: How to add List to a container

    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,470 on at
    RE: How to add List to a container

    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
    236,336 Most Valuable Professional on at
    RE: How to add List to a container

    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,470 on at
    RE: How to add List to a container

    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
    236,336 Most Valuable Professional on at
    RE: How to add List to a container

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,029

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 871 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 582 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans