BC Friday Tips #12 Code with Clear Intention

Code with clear intention

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. ๐Ÿš€

thatnavguy

Experienced NZ-based NAV Developer and Consultant with 15+ years of experience leading multiple IT projects, performing business analyst, developing, implementing, and upgrading Dynamics NAV and Business Central. Passionate to deliver solution that focuses on user-friendly interface while keeping high standard of compliance with the needs.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *