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

Add Today's Date in DateEdit Control

(0) ShareShare
ReportReport
Posted on by 435

Hi there,

           I have created a form which consist of a Grid and Inside this grid i have added one DateEdit Control with EDT = Transdate.

         When i open the form, i need to fill the DateEdit Control field with today's date.Please help.

Thanks

Regards

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Muthusamy Profile Picture
    4 on at
    RE: Add Today's Date in DateEdit Control

    Hi Mohammed,

    init the field value by using today() function to assign the current date.

    Thanks,

    Muthusamy.V

  • Suggested answer
    Mea_ Profile Picture
    60,284 on at
    RE: Add Today's Date in DateEdit Control

    Hi Mohammed Altaf ,

    On the init method of a form after super() you can write

    public void init()
    {
        super();
        DateEdit.dateValue(systemDateGet());
    }


    where "DateEdit" is name of your control. Please note that you need to set "AutoDeclaration" property to "Yes" on this control.

  • Suggested answer
    Martin Dráb Profile Picture
    236,279 Most Valuable Professional on at
    RE: Add Today's Date in DateEdit Control

    Grids are bound to a datasouce, therefore you need to initialize the table buffer and not the control itself. When you open the form, you have three options what may happen:

    1. The grid already contains records. In this case, existing records have their own value of the field saved in database; you won't initialize anything when opening the form. You'll initialize the field to the current date only when you create a new record (such as by pressing Ctrl+N).
    2. If the grid is empty and the datasource isn't configured to create a new record if empty, it's similar to previous case. There is nothing to initialize unless you create a new record.
    3. If the grid is empty and the datasource is configured to create a new record if empty, opening the form will automatically create a new record and that's when you wan to initialize it.

    As you see, it's not really opening the form; it's about creating a new record in the datasource.

    You can put such initializing logic into initValue() method. If records should always be initialized in this way, use initValue() on the table. If it's logic specific to this one form only (and shouldn't be used when new records are created in other forms), use initValue() on the datasource.

    systemDateGet() will give you the current date.

  • Mohammed Altaf Profile Picture
    435 on at
    RE: Add Today's Date in DateEdit Control

    Thanks @Martin Dráb

    thanks for you deep explanation, i have tried to write the code in initValue() method, but its not working for me.

    public void initValue()

    {

       super();

       om_displayDate_DisplayDate.dateValue(systemDateGet());

    }

    My data-source has three fields i.e. ItemID, StoreID, DisplayDate

    and Grid already contains some records.

  • Verified answer
    Martin Dráb Profile Picture
    236,279 Most Valuable Professional on at
    RE: Add Today's Date in DateEdit Control

    If a control is bound to a datasource, trying to change its value directly has no effect. As I tried to explained, you have to change the value of the table field.

    If you're using initValue() on the table (which should be your default choice), simply use this.DisplayDate = systemDateGet().

    If it's logic specific to your form (and the field shouldn't be initialized to the current date in other situations), therefore you're forced to put your code on the form, use yourDataSourceName.DisplayDate = systemDateGet().

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

#1
Community Member Profile Picture

Community Member 4

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans