Add Elements to the Role Explorer

Using the “Role Explorer” in Microsoft Dynamics 365 Business Central, you can get an overview of the features available to your Role. Each of the “Role Explorer” elements is an action, and a means to navigate Microsoft Dynamics 365 Business Central (I have heard this many times referred to as a “menu”).
Elements can be added to the “Role Explorer” by extending the Role Center being viewed. The following snippet is an example that extends the Business Manager Role to add an action that opens a page.

pageextension 50101 "Business Manager Ext" extends "Business Manager Role Center"
{
    actions
    {
        addafter(Deposits2)
        {
            action(MyCustomerList)
            {
                ApplicationArea = Basic, Suite;
                Caption = 'My Customer List';
                Image = Customer;
                Promoted = true;
                PromotedCategory = Process;
                RunObject = Page "Customer List";
                ToolTip = 'Display Customer List';
            }
        }
    }
}

Note: The code listed in this article is for demonstration purposes only 

Permanent link to this article: https://www.dvlprlife.com/2022/07/add-elements-to-the-role-explorer/

Feature Management in Dynamics 365 Business Central

With each Major and Minor update of Microsoft Dynamics 365 Business Central, new features are added to the application.
Feature Management, within a Sandbox Environment, allows an administrator to enable the preview of upcoming features, allowing users access (to test) the features in a SandBox environment before they’re activated in a Production environment.

Search for Feature Management in a SandBox Dynamics 365 Business Central Tenant and select the Feature Management page. The Feature Management displays a list of features, their expected release period, and the option to enable the feature for all users.

Read more on Feature Management in Microsoft Dynamics 365 Business Central

Permanent link to this article: https://www.dvlprlife.com/2022/07/feature-management-in-dynamics-365-business-central/

HttpClient Extension Setting in Microsoft Dynamics 365 Business Central

While using a Microsoft Dynamics 365 Business Central Extension that uses the HTTPClient, you may have seen a dialog prompting, “The extension [extension name] by [publisher name] is making a request to an external service. Do you want to allow this request?”

The extension [extension name] by [publisher name] is making a request to an external service. Do you want to allow this request?

The option chosen when presented with this prompt is saved in the database and is editable (if you want to change your “Always” response) from the Extension Configuration page with the Allow HTTPClient Requests option. The option is helpful if you accidentally choose or want to go back and modify your choice.

To change the Allow HTTPClient Requests option for an Extension:

    • Search for Extension Management within Business Central
    • Find the extension in the list
    • Click the ellipsis to open the extension menu
    • Choose Configure
    • Slide the Allow HTTPClient Requests slider to the desired value

Permanent link to this article: https://www.dvlprlife.com/2022/06/httpclient-extension-setting-in-microsoft-dynamics-365-business-central/

Set BCContainerHelper Default Configuration Values

BCContainerHelper is a PowerShell module that makes it easier to work with Microsoft Dynamics 365 Business Central and NAV Containers on Docker. The BCContainerHelper module contains many valuable functions that do much more than basic container management. I use this module in some form daily. Many BCContainerHelper module functions have switches and parameters; however, some use the default values with the options. 

You can configure BCContainerHelper default configuration values for use where applicable in the module functions.

This PowerShell script  demonstrates setting the configuration values for BCContainerHelper:

$bcContainerHelperConfig

$bcContainerHelperConfig.defaultNewContainerParameters = @{
"Accept_Eula" = $true
"Isolation" = "hyperv"
"UpdateHosts" = $true
}

$bcContainerHelperConfig | ConvertTo-Json | Set-Content "C:\ProgramData\BcContainerHelper\BcContainerHelper.config.json" 

Note: The code listed in this article is for demonstration purposes only 

Permanent link to this article: https://www.dvlprlife.com/2022/06/set-bccontainerhelp-default-configuration-values/

June 2022 Cumulative Updates for Dynamics 365 Business Central and Microsoft Dynamics NAV

The June updates for Microsoft Dynamics NAV and Microsoft Dynamics 365 Business Central are now available.

Before applying the updates, you should confirm that your implementation is ready for the upgrade and ensure compatibility with your modifications. Work with a Microsoft Partner to determine if you are ready and what is needed for you to apply the update.

Please note that SaaS customers will automatically be upgraded to 20.2 over the coming days/weeks and should receive an email notification when upgraded.

Direct links to the cumulative updates are listed here:

Dynamics 365 Business Central On-Premises 2022 Release Wave 1 Updates – Update 20.2 (June 2022)

Dynamics 365 Business Central On-Premises 2021 Release Wave 2 Updates – Update 19.8 (June 2022)

Dynamics 365 Business Central On-Premises 2021 Release Wave 1 Updates – Update 18.14 (June 2022)

Dynamics 365 Business Central On-Premises 2020 Release Wave 2 Updates – Update 17.17 (April 2022)

Dynamics 365 Business Central On-Premises 2020 Release Wave 1 Updates – Update 16.17 (October 2021)

Dynamics 365 Business Central On-Premises 2019 Release Wave 2 Updates – Update 15.17 (April 2021)

Dynamics 365 Business Central On-Premises Spring 2019 Updates – Update 36 (June 2022)

Dynamics 365 Business Central On-Premises October’18 Updates – Update 18 (April 2020)

Microsoft Dynamics NAV 2018 – Update 53 (June 2022)

Microsoft Dynamics NAV 2017 – Update Update 61 (January 2022)

Microsoft Dynamics NAV 2016 – Update 67 (July 2021)

Permanent link to this article: https://www.dvlprlife.com/2022/06/june-2022-cumulative-updates-for-dynamics-365-business-central-and-microsoft-dynamics-nav/

Validate field pattern with Regular Expression in Dynamics 365 Business Central

When accepting user input in a field, it may be necessary to validate that the value matches a particular pattern. In early versions of Microsoft Dynamics NAV, you could use the RegEx dotNet libraries to validate input against a regular expression.

The RegEx dotNet libraries are not directly available in Dynamics 365 Business Central; however, there is a RegEx Codeunit that provides functionality to use regular expressions to match text patterns. The RegEx Codeunit implements an IsMatch procedure, which you can use to validate a value against a Regular Expression.
For example, to match a pattern of three alphabetic characters followed by a hyphen and then any three alphanumeric characters (Good: ABC-D1Q, Bad: 123-ADS), the following RegEx example implementation demonstrates the use of the IsMatch procedure:

 Adjust the pattern and code to satisfy your requirements. Text version of code listed below.

field(50101; "DVLPR RegEx Code"; Code[20])
        {
            Caption = 'RegEx Code';
            DataClassification = CustomerContent;

            trigger OnValidate()
            var
                Matches: Record Matches;
                Regex: Codeunit Regex;
                Pattern,
                Value : Text;
            begin
                Pattern := '[A-Z]{3}\-[0-9,A-Z]{3}

                if Regex.IsMatch("DVLPR RegEx Code", Pattern, 0) then
                    Message('Match')
                else
                    Error('No Match');
            end;
        }

Note: The code listed in this article is for demonstration purposes only 

Permanent link to this article: https://www.dvlprlife.com/2022/06/validate-field-pattern-with-regular-expression-in-dynamics-365-business-central/

Business Central 2022 Wave 1 – In-Client Performance Profiler

With each update of Dynamics 365 Business Central, Microsoft enhances what is often referred to as the base application and enhances the development environment. Dynamics 365 Business Central 2022 Wave 1 has several exciting new features in the development environment. One of the exciting features is the In-Client Performance Profiler

In 2021 release wave 2, Microsoft added the AL performance profiler to the Visual Studio Code AL experience. The performance profiler has empowered pro developers to investigate performance as part of developing new functionality and help troubleshoot performance issues in AL code in customer environments.

In 2022 release wave 1, Microsoft takes the performance profiler even further. The in-client performance profiler is a new app page reached on its own or from the Help & Support page.

One note is that it is only possible to capture the current session for the user who starts the profiler in this release wave.

The In-client performance profiler is accessible from the Help and Support Page or by searching for Performance Profiler in the Tell Me feature of Business Central.

This tool makes it easy for consultants and customer administrators to perform initial performance investigations without involving pro developers seamlessly.
Once the In-Client Performance Profiler page is open, click the start action, and perform the operation you’d like to profile from the user session. Once the process completes, use the stop action to end profiling and display the profiler results.

The profiler will display the call tree and the amount of time consumed by each app and process within the call tree. The profiler data is precious information when determining where there may be a performance issue.

Permanent link to this article: https://www.dvlprlife.com/2022/06/business-central-2022-wave-1-in-client-performance-profiler/

Set A Windows Service Log On Account and Password with PowerShell

Repeatability is important! Right alongside that, in my opinion, is efficiency. A recent task required me to set up several Application Services setups, including setting the log on account and password. I could have done all of these manually; however, I found it more efficient and repeatable to set up a script to handle the setup.

I won’t get into the portion for the setup of the services; I’ll communicate a few ways to set a Windows Service Log On Account and Password with PowerShell.

The Set-Service cmdlet changes the properties of a service, along with the starting and stopping of a service.

Before setting the log-on account information for a service, we need to capture the credentials. The credentials can come from user input:

# Prompt for credentials
$Credential = Get-Credential

# Prompt for credentials with message
$Credential = Get-Credential -UserName domain\user -Message 'Enter Password for Service Account'

or the credentials may be in the contents of the script:

$UserName = 'admin'
$Password = 'password'
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($UserName,$SecurePassword)

Once the credentials are captured, they are set for the service:

# Enter the name of the service to set; i.e. EventLog
$ServiceName = 'EventLog'

# Stop the service
Set-Service -Name $ServiceName -Status Stopped

# Set the service credentials
Set-Service -Name $ServiceName -Credential $Credential

# Start the service
Set-Service -Name $ServiceName -Status Running

The Get-Service cmdlet retrieves the properties of a service.

If you’re using an earlier version of PowerShell and do not have the -Credential parameter available, you can use the gwmi / Get-WmiObject cmdlet:

$account = "<the account name>"
$password = "<the account password>"
$servicename = "name='<the service name>'"

$svc = gwmi win32_service -filter $servicename
$svc.StopService()
$svc.change($null,$null,$null,$null,$null,$null,$account,$password,$null,$null,$null)
$svc.StartService()

Permanent link to this article: https://www.dvlprlife.com/2022/06/set-a-windows-service-log-on-account-and-password-with-powershell/

Add Twitter Card to WordPress without Plugin

Reading this blog, one may think I focus on WordPress development and enhancements. That is not the case by any means. The focus of my career focused on the implementation of Microsoft Dynamics 365 Business Central. The concept behind this blog is to share bits of [technical] “stuff” that I encounter on my journey. The WordPress concepts come into play as I continue to enhance this site.

Sharing the content on this site on social platforms is another way to relay information that may be helpful to some. I recently became more active in the following Twitter posts and felt that it would be an excellent platform to share my blog posts. 

I went over to Twitter, pasted the link to a blog post that I wanted to share, and hoped to see a “preview” of the content. Well, I was wrong. The only thing in the “tweet” was the link to the post. After a bit of digging, I found that there is a “Twitter Card.” The Twitter Card is meta-information on the page of your site that relays to Twitter how the page preview should look in a Tweet. I found that there is a Twitter Card Validator that will alert you of any Twitter Card issues for the link that you’d like to Tweet. Of course, my post failed validation.

Several WordPress Plugins are available that add Twitter Cards to your pages, but I prefer to use as few Plugins as possible to reduce the risk of any issues. Just as I did when changing the Login Page, I opted to get the Cards onto my posts myself through functions and actions.

Add the following to your Theme’s functions.php file (replace the image url and the twitter creator tag with your image and tag):

function twittercard()
{
	if(is_single() || is_page()) {
    	$twitter_title  = get_the_title();
		$twitter_url    = get_permalink();
		$twitter_desc   = get_the_excerpt();
		$twitter_image	= 'https://www.dvlprlife.com/tweetimage.jpg?rating=PG&size=75';
		
		echo '<meta name="twitter:card" value="summary" />';		
		echo '<meta name="twitter:title" value="'  . $twitter_title . '" />';
		echo '<meta name="twitter:url" value="' . $twitter_url . '" />';
		echo '<meta name="twitter:description" value="' . $twitter_desc . '" />';
		echo '<meta name="twitter:image" value="' . $twitter_image . '" />';

		echo '<meta name="twitter:creator" value="@dvlprlife" />';
	}
}

add_action('wp_head', 'twittercard');

 

Please note that doing this without a plugin does require some programming knowledge, and before ever making any changes, you should always back up your site.

Make a note and save the code added; if the function.php file is updated and replaced, the code will need to be added to the file again. You can also look into setting child themes to keep you from losing the edit.

Permanent link to this article: https://www.dvlprlife.com/2022/05/add-twitter-card-to-wordpress-without-plugin/

Delete files within subfolders older than a certain period using PowerShell

In keeping true to the concept of this blog, “Follow the life of an ERP developer, one post at a time,” this post allows you to “follow” something that I needed to crush – deleting files older than a specific number of days or hours including subfolders.

Many moons ago, I created an application that created log files capturing event details. The log files’ sole Delete Key In Bluepurpose was to review events and troubleshoot issues when processing these events. The files are saved in a folder structure divided and grouped by Year, Month, and Event Type. The grouping is helpful for troubleshooting and finding specific transactions, but with several types of events and, at times, a decent volume, there can be a decent amount of disk space wasted; realistically, there isn’t a need to keep diagnostic logs forever. The data does become stale after a certain period.
I created this PowerShell script to delete files from a folder and subfolders older than a certain number of hours from the time of script execution:

$sourcepath = 'D:\Archive\'
$CurrDate = Get-Date
$MaxHours = -1200

Foreach($folder in (Get-ChildItem $sourcepath -Recurse  | where {  $_.PSIsContainer }))
{
    #"Folder: $folder"
    Foreach($file in (Get-ChildItem $folder.FullName | where { ! $_.PSIsContainer }))
    {
	#"File: $file"
        if($file.LastWriteTime -lt ($CurrDate).AddHours($MaxHours))
        {
	        #"Filter File: $file"
            Write-Host -ForegroundColor Yellow ($file.FullName) 
            Remove-Item $file.FullName
        }
    }
}

If you want to specify the number of days, replace:

if($file.LastWriteTime -lt ($CurrDate).AddHours($MaxHours))

with

if($file.LastWriteTime -lt ($CurrDate).AddDays($MaxDays))

Remember to replace the $MaxHours variable with $MaxDays.

Permanent link to this article: https://www.dvlprlife.com/2022/05/delete-files-within-subfolders-older-than-a-certain-period-using-powershell/