Breaking news from around the world
Get the Bing + MSN extension
Now Available in Community - MBAS 2019 Presentation Videos
Catch the most popular sessions on demand and learn how Dynamics 365, Power BI, PowerApps, Microsoft Flow, and Excel are powering major transformations around the globe. | View Gallery
2019 release wave 2 Discover the latest updates to Dynamics 365Release overview guides and videos Release Plan | Early Access Availability
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants. | Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements | ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance TechTalks | Customer Engagement TechTalks | Talent TechTalks | Upcoming TechTalks
Every now and then a developer takes the xRec bait and they’re wondering why their code doesn’t work and it usually ends up with a lot of lost time combined with a good amount of frustration.
I hope most of you do know that if you trigger the OnModify through code and xRec is used in the OnModify trigger, Rec and xRec will be the same, however it works fine when it’s triggered through the UI.
In NAV2017 and before this was ‘solved’ by a workaround: a function called OnModify with a record parameter called xRec.
Meaning you would have to either save the record in another variable before changing values or retrieve the xRec from the database and then call the OnModify function and another MODIFY(TRUE) to actually apply the changes instead of a plain and simple Rec.MODIFY(TRUE).
Let’s have a look at the implementation in NAV2017 taking codeunit 5056 and table 5050 as an example:
The OnModify trigger of table 5050 (just calling the OnModify function with xRec)
Updating a contact from a customer in codeunit 5056:
The workaround works but it’s still a bit tricky and there’s a big chance you’ll forget all of this when your head is in the code.
In NAV2018 it’s still a workaround but now it’s a proper one:
The OnModify function is still there and in the OnModify trigger of the table Rec and xRec are compared as text and if they’re equal then it will most likely be the case that the OnModify trigger has been triggered by code.
Then all there’s left to do is retrieve xRec from the database by using a FIND followed by a call to the OnModify function.
Even the OnModify function is completely obsolete and can be removed, but for some reason all the calls to this function are not (yet) refactored to the MODIFY(TRUE).
Business Applications communities