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 correctly pack and unpack objects

(0) ShareShare
ReportReport
Posted on by 170

How can I pass _args by pack / unpack methods? Like this example the caller() object reference not set... And true when I look at passed _args and what it unpacked the content is almost is mostly null or '0'.  I need to get access to formDataSource in the second static method.

    public static void main(Args _args)
    {
        MyClass::passArgs(_args.pack());
    }
        public static void testingPack(container _args)
    {
        Args myArgs = new Args();
        myArgs.unpack(_args);
        FormRun formRun = myArgs.caller();
    }

I have the same question (0)
  • Martin Dráb Profile Picture
    236,336 Most Valuable Professional on at
    RE: How to correctly pack and unpack objects

    Your code snippet shows some unrelated methods. main() calls passArgs(), which isn't mention anywhere else. Then there is testingPack(), but it doesn't seem to have anything to do with main().

    In either case, a container can't hold references to objects, such as a FormRun instance, therefore the whole idea is invalid.

  • RadekM Profile Picture
    170 on at
    RE: How to correctly pack and unpack objects

    My bad didn't noticed I made a name mistake. It should be passArgs() instead of testingPack(). Anyway I wondered because I was passing a container _args.pack() and passArgs(container) values looked valid, the references broke when I unpacked the container.

    Anyway is there a way to share or pass _args between two or more static methods? Tried to declare static args outside of method and use copyArgs() in main but looks like the second method see it just as new args.

  • Martin Dráb Profile Picture
    236,336 Most Valuable Professional on at
    RE: How to correctly pack and unpack objects

    Sure, you can pass object references between static method. But that has nothing to do with packing. Either you actually don't need any packing, or you likely wanted to ask a different question. I can't know, because you told us nothing about actual scenario.

  • RadekM Profile Picture
    170 on at
    RE: How to correctly pack and unpack objects

    This screnario is actually a continuation of my previous thread. I try runAs() method but it only accept a container as parameters. I does accept the pack() so I tried to go this way. I need to be able to use the _args from the method calling runAs() in called method and both are static.

  • Suggested answer
    Martin Dráb Profile Picture
    236,336 Most Valuable Professional on at
    RE: How to correctly pack and unpack objects

    Packing an instance of Args classs to a container and unpack it to another Args object is possible, but it won't help you with your requirement "I need to get access to formDataSource". You can't put a memory address of an object to a container. You'd need to pack the form data source object, which can't meaningfully be done.

    You need to think about what information you actually need and find a way how to put it into a container. For example, if you want to get records selected in a form, you can use MultiSelectionHelper to iterate the records, store their IDs in a Set, pack the Set to a container and pass this container to your method.

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