Skip to main content

Notifications

Announcements

No record found.

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 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().

  • Mohammed Altaf Profile Picture
    Mohammed Altaf 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.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 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.

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 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
    Muthusamy Profile Picture
    Muthusamy 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans