Dynamics Business Central / NAV Developer Digest - Vol. 493

Dynamics Business Central / NAV Developer Digest - Vol. 493

ArcherPoint’s Developer Digest focuses on Microsoft Dynamics 365 Business Central and Dynamics NAV development. This week’s volume includes Days of Knowledge Americas coming in September, checking prompt vulnerability in BC Copilot, using the Random() and Randomize() methods, and removing media orphans.

The Dynamics 365 Business Central community, consisting of developers, project managers, and consultants, collaborates across various platforms to share valuable insights. At ArcherPoint, we greatly value their dedication and expertise. To ensure widespread access to this technical knowledge, we created Developer Digest.

Mark your calendars: Days of Knowledge coming to Atlanta in September!

Days of Knowledge Americas 2024 is coming to the Loudermilk Conference Center in Atlanta, Georgia, September 12-14. Days of Knowledge is a Directions for Partners event focused on educating consultants and developers to prepare them to create quality Business Central customer solutions.

The event will include two full days of training sessions (September 13-14) plus a day of pre-conference training on September 12. The sessions will be presented by over 30 Business Central experts including ArcherPoint developers Kyle Hardin, Tom Hunt, John Long, and Matt Traxinger.

Beat the price increase by purchasing your Early Bird tickets by August 2.

Make your plans to attend Days of Knowledge Americas 2024 now!

Checking prompt vulnerability in Business Central Copilot with Prompt Shields

Many of us are familiar with SQL injections in code, a web security vulnerability that lets an attacker override or modify queries to extract or alter private information in a database.

A similar problem can occur with AI prompts. A prompt injection vulnerability can allow an attacker to access or manipulate a large language model (LLM), allowing the attacker to extract critical information or influence critical processes.

Microsoft has introduced Prompt Shields in Azure AI Content Safety API that “analyzes LLM inputs and detects User Prompt attacks and Document attacks.”

Stefano Demiliani discusses how to use Prompt Shields to help secure prompts in Azure OpenAI and Business Central Copilot in his blog, Prevent prompt injections in your Azure OpenAI and Copilots implementations.

Using the Random() and Randomize() methods in AL

Jon Long posted: I have always wondered how the System.Random() method works in AL. In my tests, I saw that Random() frequently gave me the same output (for example, GetRandomCustomer() would return the same customer for all my tests).

The trick is to call Randomize() with no parameter before calling Random(). You don’t need to call it every time you call Random, just before you start calling Random, say in a loop.

This essentially forces the System to “seed” the System.Random() functionality with the current time in milliseconds as an integer. Otherwise, I believe the System only refreshes the “seed” every hour or so.

If the following test is run without calling Randomize(), it will return the same values every time, at least for about an hour, until the System auto-refreshes the “seed.” With this code, it returns different numbers every time.

Using Randomize() and Random() in AL
Using Randomize() and Random() in AL

Mainly “Random” is used in tests, but it looks like in Production code, there are usages to generate passwords and unique values like file names.

Find out more:

System.Randomize method

System.Random method

Identifying and removing media orphans

Adding media – pictures, files, attachments – can fill up your database quickly. And if you’re not careful, they can remain as records in the Media table even though there are no references to them.

These Media Orphans add nothing to your application but can take up large amounts of valuable database capacity. And, since there are no references to them (“NO references anymore to ANY record in ANY table of ANY extension”), they are virtually impossible to isolate and remove.

Waldo (Eric Wauters) has stumbled upon an undocumented feature in Business Central since v23.5: how to remove Media Orphans.

Read his blog, Cleaning up Media Orphans with the Data Administration tool in Business Central, to find out more – and take note of his references at the end of the blog article.

++++++++++++++++++++

Are you interested in Dynamics NAV and Business Central development? Check out our collection of NAV/BC Development Blogs.

Read “How To” blogs from ArcherPoint for practical advice on using Microsoft Dynamics NAV and Dynamics 365 Business Central.

Trending Posts

Stay Informed

Choose Your Preferences
First Name
*required
Last Name
*required
Email
*required
Subscription Options
Your Privacy is Guaranteed