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 :
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
    301,030 Super User 2025 Season 2 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
    301,030 Super User 2025 Season 2 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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans