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)

Update a AX Form data field that is bound to data source

(0) ShareShare
ReportReport
Posted on by

I need to set the value for ToDate to be the value of FromDate field when FromDate is selected by the user. both are FormDateControl controls. my code in fromDate.TextChange event handler is like toDate.DateValue(this.DateValue()), but it doesn't workout. from code degging the value of toDate is updated but it still shows the old value on the screen. In MSDN I found

"Note

This property (DateValue) is not used if the DataSource and DataField properties are set."

this means it doen't work to try to update the control, I need to update the datasource, which I can somehow get it from element.datasource() method. is this correct thinking? any advices are greatly appreciated.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Dick Wenning Profile Picture
    8,705 Moderator on at

    override the modified method on the fromfield

    on this event set the todate

    example

    public void modified()

    {

       super();

       if ((aifAction.ActionType == AifActionType::SendXml) && (aifAction.ExternalAction == ''))

       {

           aifAction.ExternalAction = aifAction.ActionId;

       }

    }

    on the end use table_ds.refreash()

  • Community Member Profile Picture
    on at

    Thanks Dick. I don't get it that in modified() you uses aifAction (where to get this instance?). this issue is on a regular Form, there is no AIF operations involved.

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    look at  aifaction form (AOT), open datasource node , open field and on the field look at the methods

    the aifform is just an example

  • Community Member Profile Picture
    on at

    Sorry Dick, I am trying to understand your suggestion, again, how to get the "aifAction" in my case? is it regarding to the form instance? can you give a little more code on getting the instance?

  • Dick Wenning Profile Picture
    8,705 Moderator on at

  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Kevin, forget about aifAction., it's just a name. The point is to set a value to a buffer field (e.g. myTable.ToDate = myTable.FromDate) rather than directly directly to a form control. The name of the buffer is the same as the name of your form data source, you don't have to do anything for that.
    If the logic is applicable to all forms, you can put it into modifiedField() method on the table (where you use this to refer to the instance).

  • Community Member Profile Picture
    on at

    Thanks for both of you!

    As you directed I put following code under the datasource datafield's modified event, it works out. Before I put logic in the UI control's modified event and it doesn't work. btw, I am still wonder I didn't use the if() clause as Dick mentioned, because I am still not get it now,  is it a concern? Thanks again.

    public void modified()

    {

       statementTable.transToDate = statementTable.transFromDate;

       super();

    }

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    public void modified()

    {

      super();

      statementTable.transToDate = statementTable.transFromDate;

      statementTable.write();

      statementTable_ds.reread();

    }

  • Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Kevin, if you want to update ToDate every time when FromDate changes, you obviously don't need any conditional logic (such as if).

    I would also warn before the last code snippet - it's usually bad idea to save a record in modified() (although exception exist). It's better to leave saving to users, when they're ready and expect so. Otherwise they may change a field and get errors about mandatory fields or other validations.

  • Community Member Profile Picture
    on at

    Thank you both very much for the valuable points. I agree with you Martin the point to keep up with the user's expecation with coding. Actually I didn't include following two statements as shown in Dicks latest code snippet, but it saves any time I change the FromDate, and the ToDate is changed accordingly by the code, then I close the form and AX, restart AX and open the form, the change is reflected. I believe upon the form's close event the data buffer is synced back to the database, behind the scene.

    statementTable.write();

    statementTable_ds.reread();

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans