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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    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.

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    305,196 Super User 2026 Season 1 on at

    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'.

  • Sandri Profile Picture
    3,850 on at

    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
    305,196 Super User 2026 Season 1 on at

    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'.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 21

#2
dserp Profile Picture

dserp 4

#2
dekion Profile Picture

dekion 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans