Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Getters, setters and default values.

(0) ShareShare
ReportReport
Posted on by 3,850

Hello

I have wrote a Class with method who get and set values to a variable like this.

Public SerialNumber serialNumber(SerialNumber _serialNumber = serialNumber)

{

serialNumber = _serialNumber;

return serialNumber;

}

But I want to set a default value "999999" to the variable: serialNumber.

What is the best way to do that?

Should I implement the default value to this get-set method, and if so how do I do that?

But should I write another method where I assign "999999" to the serialNumber variable before i use the above method?

*This post is locked for comments

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,861 Super User 2024 Season 2 on at
    RE: Getters, setters and default values.

    Hi Sandri,

    You can use Args, but that is useful when you have a (temporary) table. If you want to communicate some values only (no table), you can better construct the class from the form and use some 'parm...'- methods which you can create on the class.

    There is a nice sample within the form and class both named: 'UnitOfMeasureCalculator'.

  • Sandri Profile Picture
    Sandri 3,850 on at
    RE: Getters, setters and default values.

    Hi Andre.

    The answer about default values is yes, it's always same values and user can change is trough form if he want or he can leave it unchanged.

    -So I thought about the solution by writing a class, assign default values in methods, and use Args to communicate between Classes and Forms where the default values is displayed.

    -Do you have any comments on that?

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,861 Super User 2024 Season 2 on at
    RE: Getters, setters and default values.

    Hi Sandri,

    The answer of Nitesh will work when the default is really always the same value. If you have a process where the last user values needs to be retrieved and only defaulted when there are no user values found, you can add an override method called 'initParmDefault' on you class.

    See a sample at the class 'ProdParmStartup'.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Getters, setters and default values.

    actually for this kind of Getters, setters methods, the variable serialNumber use to be global variable and defined in Classdeclaration

    best practice to initialize the global variable use to be when class object is initialized,

    any class when it get initialized it calls the method called new()

    so in new() method og the class.. write following statement

    serialNumber = "999999";

    hopefully this will solve your problem.

    Please validate.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey Pt 2

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,861 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,540 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans