Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Dialog run() passing parameters

Posted on by 150

Can I pass values of dialogfields to another method in another class?

Eg I have a dialog class

Testdialog extends runbase

{

Object dialog ()

{ Dialogfield testfield;

...//remaining part of my code

}

Run()

{ Testclass tclass = new testclass()

Tclass.tmethod(testfield);

}

}

//My second class

Public void  Testclass()

{

Public static tmethod(str test field)

{

//My code

}

Is this okay?

  • WillWU Profile Picture
    WillWU 22,344 on at
    RE: Dialog run() passing parameters

    Hi PrachiGupta97,

    As Martin said,  you don’t have any code for serialization.

    You could use the SysOperation framework instead so that you don't have to implement serialization.

    If you have to use the RunBase framework, you have to learn about the pack() and unpack() methods.

    Pack and unpack is Dynamics language for serialization -- putting object-specific data in a writeable format and later reading it back to create an object in the exact same state.

    https://docs.microsoft.com/en-us/dynamicsax-2012/developer/pack-unpack-design-pattern?redirectedfrom=MSDN

    You could find many examples class in AX, please have a look at the Tutorial_RunbaseBatch class.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 225,513 Super User on at
    RE: Dialog run() passing parameters

    Your class is not a dialog class - it's a RunBase class. It uses Dialog and DialogField classes to create a dialog and get input from user and it's only one part of what it does.

    Unfortunately you didn't paste your code correctly (using Insert > Insert Code in the rich formatting view), therefore it lost indentation and it's very difficult to read. Let me post it again in a better way (and with a few fixes:

    TestDialog extends RunBase
    {
    	Object dialog()
    	{
    		DialogField testfield;
    		...//remaining part of my code
    	}
    
    	run()
    	{
    		Testclass tclass = new TestClass()
    		Tclass.tmethod(testField);
    	}
    }
    
    
    
    //My second class
    public void  TestClass()
    {
    	public static tmethod(str testField)
    	{
    		//My code
    	}
    }

    While the idea is possible in general, you have multiple bugs there.

    First of all, tmethod() expects a string, while you're trying to pass a DialogField object. Finding this kind of errors is easy - simply compile your code and look at compilation errors/

    Also, you forgot to implement serialization. If you fill a dialog field on client and execute run() on server, you won't have access to anything in the dialog. You must either learn how to use RunBase, or rather use the newer replacement of the RunBase framework - the SysOperation framework. It has quite a few benefits and this is one of them - it deals with serialization for you.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,773 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,513 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans