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)

Is the update method the right one to use?

(0) ShareShare
ReportReport
Posted on by

I ran an X++ job to update the EFT field (ADCEFTNumber) on every customer record with the PartyNumber from the DirPartyTable but an unwanted side-effect was the Business unit financial dimension being wiped out. I had to get our external AX support team to replace the business unit. They mentioned that the ".update" method that I used could have been the cause.

I've used this before many times for similar record updates without issue. What could have caused this and what should I use instead of ".update"?

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Hi AXatak,

    You have to provide the detailed script you used to be able to see what could be wrong.

  • Community Member Profile Picture
    on at

    I posted this once already and refreshed to check it persisted. Now 10 minutes later it seems to have disappeared so here goes again:

    static void NC_customer_eft(Args _args)
    {
    CustTable myCustTable;
    DirPartyTable myDirPartyTable;
    str eft;
    int updated;
    ;
    updated = 0;
    ttsBegin;
    while
    select
    forUpdate
    AccountNum, VATNum from myCustTable
    join myDirPartyTable
    where ( myDirPartyTable.RecId == myCustTable.Party
    && myCustTable.ADCEFTNumber == " " )
    {
    eft = '1' + subStr( myDirpartyTable.PartyNumber,2,10 );
    myCustTable.ADCEFTNumber = eft;
    myCustTable.update();
    updated++;
    }
    info( 'Total updated = ' + int2str( updated ) );
    ttsCommit;
    }

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

    In this case if there is no additional logic connected to your field in case the value changes, you should have used validateWrite() then if return value for that is true, call the doUpdate(). By using update(), you could trigger unwanted business logic such as the one you've experienced.

    Before calling update you must always check the standard overrideable methods (insert, modifiedfield, update, write), and also their event subscriptions and walk through the code to see what is the impact of your doing.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    There is no business logic in the update method of the CustTable related to the financial dimensions. I do think the problem is caused by using a field list in your select statement.

    You used: while select forUpdate AccountNum, VATNum from myCustTable.

    This will retrieve only two fields and have all other fields empty (also the DefaultDimension field). On update it can indeed lose all not retrieved fields.

    Try the same without a field list: while select forUpdate myCustTable.

  • André Arnaud de Calavon Profile Picture
    301,020 Super User 2025 Season 2 on at

    Another important note: Test your jobs in a test environment first before applying it on your production environment.

  • Community Member Profile Picture
    on at

    Thanks André, you were right and retrieving all fields is the answer.

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