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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Instances of type 'InitialQueryParameter' cannot be added to a container

(0) ShareShare
ReportReport
Posted on by

pastedimage1645697249711v1.pngpastedimage1645697281160v2.png

Like that,I wanna add a query into container, but throw this error!

Is there someone who knows what the problem is?

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    You can't meaningfully pack object refences - they're just addresses in memory and they would be useless when you try to unpack the container. You need to pack the object itself to a container.

    The Query class has pack() method for this purpose.

    In unpack(), you'll pass the packed query to Query's constructor.

    By the way, if it's a new class that you're developing, thing again if this is the best possible design. Wouldn't it be much easier if you used the SysOperation framework, created a data contract class instead of such a macro and avoid implementing of pack() and unpack() methods by yourself?

  • jameszhang Profile Picture
    on at

    Thanks for your suggestions. This is a platform issue where form opening from a workspace tile is not taking into consideration the query from the menu item. I'm trying to add initialQuery into container since Args.pack() doesn't support the initialQuery,  if we don't add query to container instead shell we add query when create Args?

    pastedimage1645756430454v1.png

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    I'm sorry, but I don't understand what you mean by "Args.pack() doesn't support the initialQuery", I don't know from which class was the code you showed before and I also don't know where the create() method (from your last screenshot) is defined. Could you give us some context for your questions, please?

  • jameszhang Profile Picture
    on at

    The code I showed all came from Args.xpp, which is used to pass arguments such as a name, a caller, and parameters. Forms, reports and queries all use this class as their first argument in the constructor. 

    pastedimage1645773797308v1.png

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    It seems to me that the bug is in your code and not in Args class. You said that you're trying to add initialQuery into container, and that the part that doesn't work, for reasons that I explained above. Did you understand my explanation? If so, you know the cause and should have some idea about how to fix it.

    Thing carefully whether extending Args is safe enough, because it's used at a huge amount of places. If you think it is, you need to extend pack() and unpack(), as discussed in my first reply.

  • jameszhang Profile Picture
    on at

    pastedimage1646290531961v1.png

    I understood what you said, but I don't know how to make class InitialQuery be packable and unpackable since it cause the problem that I can not add it to container.

    Could you give me some suggestions, please?

    Thanks for help again, btw.

  • Suggested answer
    Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    Sorry, I didn't realize that we aren't talking about the Query class.

    It'll be slightly more work, but it's nothing impossible.

    First of all, decide which properties of InitialQueryParameter you need to support. I'll assume that you want just the query.

    In that case, you need to get a query from InitialQueryParameter and call its pack() method. That's easy:

    container packedQuery = initialQuery().query().pack();

    When unpacking the object, you need to create an InitialQueryParameter instance from the packed query. That's not difficult either:

    initialQuery = InitialQueryParameter::createByQuery(newQuery(packedQuery));

    Note that you can use SysPackExtensions class to add your values to the standard contain in an extension of pack(), and extract your packed values in unpack().

  • jameszhang Profile Picture
    on at

    I got confused about what you mentioned, I  know Args.pack doesn't support packing the initialQuery. To make this work we would need to add this to pack, unpack, and copyFrom. The InitialQueryParameter.cpp class would also need to be made packable/unpackable. But I don't know how to add container to .cpp?I‘m not familiar with that, could you give me some more details about these? Thanks a lot!

  • Martin Dráb Profile Picture
    237,976 Most Valuable Professional on at

    You're wrong in thinking that "InitialQueryParameter class would also need to be made packable" - my solution above doesn't need that. It implements it in an extension of Args class.

    You can add packing methods to InitialQueryParameter class, but you can't change code of kernel F&O class (nor any other standard class). You would need an extension.

    If you're not familiar with extensions and you're trying to change standard classes, please stop immediately, because you'll never be able to deploy such a solution. Instead, please read about Class extension model in X++.

  • jameszhang Profile Picture
    on at

    if I have to use macro structure to pack the InitialQuey, how to add the query in there? That troubles me a lot why I can not just pack the instance of InitialQuery .

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans