
It’s time for #BCFridayTips for #msdyn365bc developers!
Code with Clear Intention.
When you’re writing a code, it’s not just you who will read it. It’s important to ensure your intentions are crystal clear.
Let’s look at an example:
𝗥𝗲𝗰𝗼𝗿𝗱.𝗠𝗼𝗱𝗶𝗳𝘆(𝗥𝘂𝗻𝗧𝗿𝗶𝗴𝗴𝗲𝗿)
The RunTrigger parameter is optional. If left unspecified, it modifies a record without executing the code in the OnModify trigger.
While it’s best practice to run the trigger, there are times and valid reasons when you might not want to.
Instead of:
Record.Modify();
Use:
Record.Modify(𝗳𝗮𝗹𝘀𝗲);
Why?
✅ 𝗖𝗹𝗮𝗿𝗶𝘁𝘆: Being explicit is better than being implicit. In this case, the intention is not to run the trigger.
✅ 𝗔𝘃𝗼𝗶𝗱𝗶𝗻𝗴 𝗮𝗺𝗯𝗶𝗴𝘂𝗶𝘁𝘆: Record.Modify() could mean two things: You either don’t want to run the trigger, or you forgot to run it.
✅ 𝗠𝗮𝗶𝗻𝘁𝗮𝗶𝗻𝗮𝗯𝗶𝗹𝗶𝘁𝘆: Without the parameter, another developer might assume you made a mistake and try to fix it by running the RunTrigger, which could introduce bugs.
Always remember that even minor things can make a difference.
Don’t forget to share this post with others ♻️ and follow for more tips in future. 🚀