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)
Answered

Calling Update() method in modified() method

(0) ShareShare
ReportReport
Posted on by 931

Hi Experts,

Can we call update() method in the Modified() method?

In my scenario, I am adding a new field in smmBusRelTable and CustTable, the value of this field need to be synced when i enter the values in any one of the above forms (i.e) whenever i enter the value in my field in smmbusreltable form, this value should be upated to the CustTable and vice versa.

Can i use modified() method and their i assign the values like

CustTable.Myfield = smmBusRelTable.MyField;

custTable.update();

Or is their any other way to achieve my requirement. Please advice.

Thanks,

Rusty.

*This post is locked for comments

I have the same question (0)
  • veera seenivasan Profile Picture
    575 on at

    Hi Rusty

                  It is possible to write update operation in modified method

    public void modified()

    {

       super();

       if(smmBusRelTable.MyField)

       {

           ttsBegin;

          CustTable.Myfield = smmBusRelTable.MyField;

           CustTable.update();

          CustTable_ds.refresh();

          CustTable_ds.research();

           ttsCommit;

       }

    }

  • Verified answer
    DavidGunawan Profile Picture
    1,381 on at

    Hi Rusty,

    To achieve the objective, I suggest you to call doUpdate() in update() method.

    Sample

    CustTable.update()

    {

    super();

    smmBusRelTable.MyField = CustTable.MyField;

    smmBusRelTable.doUpdate();

    }

    smmBusRelTable.update()

    {

    super();

    CustTable.MyField = smmBusRelTable.MyField

    CustTable.doUpdate();

    }

    Regards

  • Verified answer
    Nishant2408 Profile Picture
    705 on at

    Hi Rusty,

    It is not a good practice to call an update in modified().

    Instead of using modified you can write your code in update() of the table itself by comparing orig() and current value of the field you are updating.

    if (this.orig().myfield != this.myfield) //this : specifies smmBusRelTable

    {

        custable.myfield = this.myfield;

        custTable.doupdate(); //if this is just a single filed value which is not affecting any        

                                            //other transaction doupdate() can be used in place of update.

    }  

    Do write validation also for the field in validateField() method of the respective table based on the type of the value you are entering.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    I agree with Nishant. You should only change a value pair in another table if validations have passed. For modified, only validateField() is being called. However the stronger logic is usually implemented in validateWrite, which is triggered by update/insert. So you should place your code there, once general validations have passed on saving the record, you could update your pair as well.

    To implement it correctly, I would do it in an event handler subscription on the update method.

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

    By the way, I've discussed problems of this design in mu blog post modifiedField() and database consistency. You don't want to update records from modified(), because modified() doesn't mean that the record will ever be saved.

  • ThivaKar Profile Picture
    931 on at

    Thank you all for your Advice :)

    Thank you very much .

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
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans