Executing Dynamics 365 Finance Post Refresh Tasks using Custom Service and D365.Integrations Tools

Currently when copying PROD data to a lower environment like a Tier2 sandbox or a cloud hosted dev box, there is no standard way of how the data copied will be cleansed and how PROD specific endpoints will be updated to point to TEST endpoints. Some customers do it manually(yup!), some using a SQL script(requires JIT access SQL if doing on a tier2 environment) and some using a custom service.

In this post, I will solely be talking about how I was able to accomplish this with a custom service which can be called from an Azure Devops pipeline using a PowerShell script using D365.Integrations tools. This will be a two part process:

Develop a Custom Service in D365

Note that here I will not talk about how to create a customer service in Dynamics 365 Finance. For that Peter has done a splendid job explaining how to accomplish that in his blog post here Create a Custom Service in D365

When creating this service and before running the code to take request object to perform actions, a validation should be added so that the code in this service is never accidently run in a PROD environment.

Below is an example of the service class showing how I did it.

using Microsoft.Dynamics.ApplicationPlatform.Environment;
public class ABCDataCleanupServiceClass
public ABCDataCleanupResponse runCleanUpTasks(ABCDataCleanupRequest _request)
    CustParameters  custParametersTable;
    var response = new ABCDataCleanupResponse();
    const str tier2sandbox      = "sandbox.operations.dynamics.com";
    const str axcloudmachine = "axcloud.dynamics.com";
        //Start with validating that code only runs in a non-PROD environment
        IApplicationEnvironment env = EnvironmentFactory::GetApplicationEnvironment();
        str currentUrl = env.Infrastructure.HostUrl;
        if (strContains(currentUrl, tier2sandbox) || strContains(currentUrl, axcloudmachine))
            //Code goes here
                    select forupdate custParametersTable;
                    custParametersTable.MandatoryTaxGroup = _request.parmMandatoryTaxGroup();
                    response.parmDebugMessage("Param updated"); 
                catch (Exception::CLRError)
                    System.Exception interopException = CLRInterop::getLastException();
    catch (Exception::CLRError)
        throw error('This a production environment');
    return response;

Create an Azure DevOps Pipeline

In an Azure devops pipeline, create a new task of type PowerShell to install required tools. See script below:

Install-PackageProvider nuget -Scope CurrentUser -Force -Confirm:$false
Install-Module -Name AZ -AllowClobber -Scope CurrentUser -Force -Confirm:$False -SkipPublisherCheck
Write-host "AZ INSTALLED"
Install-Module -Name d365fo.integrations -AllowClobber -Scope CurrentUser -Force -Confirm:$false

Create a separate PowerShell task or use the same as per your need to call the custom service using Invoke-D365RestEndpoint. Note that before this custom service can be accessed by the script, enable the Azure App ClientID in D365 by going to Azure Active Directory Applications and assign it to a service account with system administrator role. To register the app in Azure, this blog has step by step instructions on how to do it. App Registration in Azure

Finally, below is an example for the script that has the request parameters in form of a JSON and passed as Payload to the function Invoke-D365RestEndpoint

$Payload = '{
    "_request" :
        "DataAreaId": "USRT",
        "MandatoryTaxGroup": "true"
$oDataToken = Get-D365ODataToken -Tenant $Tenant -Url $D365EnvironmentURL  -ClientId $ClientId -ClientSecret $ClientSecret #-RawOutput -EnableException
Invoke-D365RestEndpoint  -ServiceName "ABCDataCleanupServiceGroup/ABCDataCleanupService/runCleanUpTasks" -Payload $Payload -Tenant $Tenant -Url $D365EnvironmentURL  -ClientId $ClientId -ClientSecret $ClientSecret  -Token $oDataToken

Payload variable here contains parameters that will be passed to the custom service in D365 as a JSON

D365EnvironmentURL here will be the D365 environment where these tasks are to be performed

oDataToken here is being generated for D365 URL using the function Get-D365ODataToken included in d365.integations tools

Once the script is run in this example, it would have updated this parameter

Parameter updated in D365

Are you doing something similar or have any suggestions to improve this further? Let me know in comments.

MacOS + Dynamics 365/Power Platform…whats missing?

Without going into the debate of which OS is better for a desktop computer, you may find yourself in a situation where you are using MacOS and involved in work that is related to Microsoft technologies like Dynamics 365 and/or Power Platform and wonder if everything will work in similar way as it would on a Windows. To answer that, in my experience below are few things that I found which had an Windows OS requirement and I had to switch either to a spare Windows that I had or use a VM.

Workflow Editor for Dynamics 365 Finance & SCM

When dealing with D365 Finance and Operation(or new names Finance and Supply Chain Management), you may have to build workflows for certain business processes. To be able to do that Workflow Editor is used which actually is a one-click application which won’t work on a MacOS.

Open in Excel

If looking to manipulate any data by open a form/list page in Excel on MacOS, you’ll encounter an error saying ‘This add-in is currently not available for use on your device’. This functionality/add-in is also only available to work on Windows.

Management Reporter Designer

Recently while working on a request from finance team to modify one of their financial report I stumbled upon a similar to workflow editor limitation where the management reporter designer won’t open on a MacOS computer and required Windows

Regression Suite Automation Tool (RSAT)

With all the ever growing need to customize D365 Finance, SCM and MPOS/CPOS to handle specific business scenarios comes a challenge where regression testing may become hectic and super time consuming. Thankfully Microsoft has a tool to automate such testing using the RSAT tool (which I personally love) but if you plan to use it on MacOS, you’re out of luck. RSAT requires Windows to run.

Power Automate Desktop

Isn’t it fun to see how Power Platform is evolving? And how easily several of your legacy repetitive tasks can so easily be automated so you can focus on other stuff? If you’re like me, you would have come across a task or two where you may have had to automate a process on a computer instead of running it on Power Automate as a cloud flow. If yes, Power Automate Desktop(it’s pretty slick and worth checking if you haven’t so far) is your tool however to use this, Windows OS will be required.

For me, thankfully it was just the development part where I ran into this requirement so I just used a Windows computer instead to develop and then my actual computer where the tool had to run was already a Windows.


Though a general tool, worth mentioning here as while working with D365 one may need to have a visual representation of business processes and architecture. For this purpose what better tool then Visio! Though some alternate tools are available for MacOS and even Power Point to some extent, I still felt the gap.

Have you come across anything that did not work for you on MacOS? Let me know in comments.

Convert Date To Julian In D365 Electronic Reporting Formula Editor

Often when talking to third-party systems/softwares, there is a requirement to transmit a Julian date in the file. A similar requirement here I had to pass today’s date formatted in Julian in the EFT file which was being generated using Electronic Reporting in Dynamics 365 Finance. To accomplish this, I used below formula in formula editor of electronic reporting. I am using today’s date here however as per your need, you can change that to a date from a data source/field as needed. 


So today’s date, 5/12/2020 gets converted to Juian date 20133

Accessing Website as an App using Edge

Recently a user reached out asking if it is possible to pin specific Dynamics 365 Finance – Customer Service page to task bar so that instead of going to the browser every time and then clicking on the specific URL, that specific form is readily available with a single click.

 I recalled I’ve done something similar in Chrome browser to add twitter but in case of D365, the option wasn’t available. However the new Edge browser from Microsoft, which comes pre-installed in Windows 10 gives us an option to install as app option for pretty much any website. Follow along below quick steps to accomplish this.

1. Go to the website you want to access as an app. Click three dots on the top left of the browser > Apps > Install This Site as an App

2. Give it a name and click Install

3. You should at this point see a new app window pop-up with your desired website. You can at this point pin it to taskbar by right clicking on the icon in the taskbar.

Are you a macOS user? No worries!

Same steps apply there as well and all you’ll need is Edge browser installed. Once installed, go to right click > Options > Keep in Dock to add this app to your dock.