Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

Update_Recordset and SkipDataMethods still calling update method

Posted on by

I'm working in AX 2012 R3.  I have a table with an overridden update method that does an update_recordset on the same table for records that do not have the same RecId.  When the user makes a change to a column in one row, all other rows get updated with the modified value.  We have skipDataMethods being called on the table buffer prior to the update_recordset.  The intention is that calling skipDataMethods will avoid an infinite loop of updating or update conflicts on the table.  However, recently we found that our update_recordset is degrading to row by row updates and creating some update conflicts because each row being updated was somehow calling the update method which triggered the same update over and over, despite having skipDataMethods called prior to the update_recordset.  I was confused as to why the update method was being called so I just started trying stuff.  I added a call to skipEvents and suddenly this works as desired, the update method is no longer called for each updated row.  There are no event handlers on any of the methods on my table so I'm not sure why skipEvents is necessary.  Does anyone know why I might need to call skipEvents to stop the data methods from firing when I already have skipDataMethods called?  I believe this has been working fine in the past several years.  I'm not sure if a somewhat recent update to R3 has caused the issue we're seeing.  I'm not a huge fan of this requirement/design but I've inherited the maintenance of this code and I'm trying to help our users get past this error.  Adding skipEvents seems to work but I'm unclear why it was needed.  Any insight would be greatly appreciated.  

Also, I attempted to reproduce this issue creating a new table with a couple fields and applying this pattern.  Testing this out with a simple job to update a row and seeing it update the other rows in the table is working fine with only the SkipDataMethods and I didn't need the skipEvents.  So I'm at a loss as this is inconsistent with what I see on the issue that my user reported. 

The code looks like this: 

public void update()

{

MyTable myTable;

super();

// adding this line seems to fix the issue- i'm not sure why

myTable.skipEvents(true);   

// i am unsure why i need skipEvents when skipDataMethods should suffice

myTable.skipDataMethods(true);    

// despite skipDataMethods, this calls the update method for each row being updated unless I added skipEvents

update_recordset myTable

setting myField = this.myField

where myTable.RecId != this.RecId;

}

  • Suggested answer
    RE: Update_Recordset and SkipDataMethods still calling update method
    [quote user="Brawndo"]

    I'm working in AX 2012 R3.  I have a table with an overridden update method that does an update_recordset on the same table for records that do not have the same RecId.  When the user makes a change to a column in one row, all other rows get updated with the modified value.  We have skipDataMethods being called on the table buffer prior to the update_recordset.  The intention is that calling skipDataMethods will avoid an infinite loop of updating or update conflicts on the table.  However, recently we found that our update_recordset is degrading to row by row updates and creating some update conflicts because each row being updated was somehow calling the update method which triggered the same update over and over, despite having skipDataMethods called prior to the update_recordset.  I was confused as to why the update method was being called so I just started trying stuff.  I added a call to skipEvents and suddenly this works as desired, the update method is no longer called for each updated row.  There are no event handlers on any of the methods on my table so I'm not sure why skipEvents is necessary.  Does anyone know why I might need to call skipEvents to stop the data methods from firing when I already have skipDataMethods called?  I believe this has been working fine in the past several years.  I'm not sure if a somewhat recent update to R3 has caused the issue we're seeing.  I'm not a huge fan of this requirement/design but I've inherited the maintenance of this code and I'm trying to help our users get past this error.  Adding skipEvents seems to work but I'm unclear why it was needed.  Any insight would be greatly appreciated.  

    Also, I attempted to reproduce this issue creating a new table with a couple fields and applying this pattern.  Testing this out with a simple job to update a row and seeing it update the other rows in the table is working fine with only the SkipDataMethods and I didn't need the skipEvents.  So I'm at a loss as this is inconsistent with what I see on the issue that my user reported. 

    The code looks like this: 

    public void update()

    {

    MyTable myTable;

    super();

    // adding this line seems to fix the issue- i'm not sure why

    myTable.skipEvents(true);   

    // i am unsure why i need skipEvents when skipDataMethods should suffice

    myTable.skipDataMethods(true);    

    // despite skipDataMethods, this calls the update method for each row being updated unless I added skipEvents

    update_recordset myTable

    setting myField = this.myField

    where myTable.RecId != this.RecId;

    }

    [/quote]

    I know this is an old post but still it could be beneficial for someone.

    SkipDataMethods only wont work, as there can be eventHandlers  associated to the methods.

    So it always safer to call as below, but again it depends on your requirement as well.

    private static void skipLogAndDataMethods(
    Common _record)
    {
    _record.skipDatabaseLog(true);
    _record.skipDataMethods(true);
    _record.skipEvents(true);
    }

  • Greg's Mom Profile Picture
    Greg's Mom on at
    RE: Update_Recordset and SkipDataMethods still calling update method

    Thank you, Nikolaos.  I agree with your statements.  I did simplify the requirement a bit in my description.  It's not exactly the same value in every row.  The requirement is that if a user changes the description on one line then other lines with the same activity number and project should be updated to match.  As you stated, a refactor of this design would be good.  

    However, I'm more curious why calling skipUpdateMethods would not work in this instance and why I had to call skipEvents to stop the update_recordset from falling back to row by row.  My understanding is skipUpdateMethods should be enough here since there are no events on my table methods.  

  • nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Update_Recordset and SkipDataMethods still calling update method

    Update_recordSet will fall back to row by row, if update method is overridden.

    Your customization sounds strange. Why store this same info in all records? If it's always the same for all records, store it in a separate table. This way you need exactly one record.

    Your current solution is asking for trouble such as deadlocks, or inconsistent data (your code is skipped if anyone calls doUpdate).

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,986 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,588 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans