Dynamics NAV / Business Central Developer Digest - Vol 372

Dynamics NAV / Business Central Developer Digest - Vol 372

ArcherPoint's Developer Digest focuses on Microsoft Dynamics 365 Business Central development and Dynamics NAV development. In Developer Digest Volume 372, we discuss how to find out who is connected to a server and developer-only tools.

The Dynamics NAV and Business Central community, including the ArcherPoint technical staff, is made up of developers, project managers, and consultants who are constantly communicating, with the common goal of  sharing helpful information with one another to help customers be more successful.

As they run into issues and questions, find the answers, and make new discoveries, they post them on blogs, forums, social media...so everyone can benefit. We in Marketing watch these interactions and never cease to be amazed by the creativity, dedication, and brainpower we’re so fortunate to have in this community—so we thought, wouldn’t it be great to share this great information with everyone who might not have the time to check out the multitude of resources out there?

So, the ArcherPoint Microsoft Dynamics NAV/BC Developer Digest was born. Each week, we present a collection of thoughts and findings from NAV/BC experts and devotees around the world. We hope these insights will benefit you, too.

Finding Out Who's Connected to Servers

The latest Developer Tip of the Day: “Suppose you have a load balancer in front of two identical BC OnPrem servers. Who's connected to each server? This little PowerShell script can tell you.

Get-NAVServerSession -ServerInstance 'BCProd' |`
Sort-Object -Property UserID,ServerComputerName |`
Format-Table -Property UserID,ServerComputerName,SessionID,LoginDatetime
$localhost = "$env:computername.$env:userdnsdomain"
$localhost = $localhost.ToLower()
$dt = New-Object System.Data.Datatable
$dt = Get-NAVServerSession -ServerInstance BCProd
$counter = 0
$counter2 = 0
ForEach ($connection in $dt) {
$nst = $connection.ClientComputerName
$nst = $nst.ToLower()
if ($nst -eq $localhost) {
$counter += 1
}
else
{
$counter2 += 1
}
}
Write-Host "APP01 $counter"
Write-Host "APP02 $counter2"

Developer-Only Tools For Doing “Special” Things

Another Developer Tip of the Day: “Sometimes you need a small tool to do something special to a customer database—maybe patching imported data, or perhaps run a test process in a test database. I create a Page with large buttons that each have code behind them. But sometimes that code is potentially dangerous, especially in a Production database. One example is a Delete From Table button I have, where you can enter a table number, and it will delete all records in that table. Useful in Test, not so good in Production (Table 17, anyone?) So, I added a couple of layers of protection. First, if you aren't SUPER, the Page just exits. Second, it checks to make sure you aren't in the Production database. I have not figured out a way to tell the difference between Test and Production other than the database name, so I just hard coded that. This is the OnOpenPage trigger:

action("Delete from Table")
{
Visible = ImportVisible;
}
trigger OnOpenPage();
var
DatabaseName: Record "Database";
XYZFunctions: Codeunit "XYZ Global Functions";
begin
if not XYZFunctions.IsSuperUser() then
Error('');
DatabaseName.SetRange("My Database", true);
DatabaseName.FindFirst();
ImportVisible := (DatabaseName."Database Name" <> 'Business Central Production');
end;

Matt T adds: “There's a codeunit named ‘Environment Information’. I haven't looked at it in a lot of detail, but there are functions like IsOnPrem, IsSaaS, IsSandbox, IsProduction. I don't think it publishes any events, so you get what you get in terms of what the functions return.”

Interested in Dynamics NAV and/or Business Central development? Be sure to see 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