Why deep links don’t work in batch in Dynamics 365 for Finance and Operations

You can create shareable and secured URLs (aka deep links) to forms in Dynamics 365 for Finance and Operations using URL Generator, i.e. the UrlGenerator class. Deep links can be embedded in reports, emails, external apps, etc.

A deep link points to a specific form in D365FO, but it can also contain parameters to filter data showing on the opening form. For example, we can create a deep link that opens the Customers form but showing only a specific customer.

Learn more on how to create deep links in Microsoft documentation >>

Please note that the following line of code doesn’t work in batch, because the SessionContext object instance is null when running in batch:

var currentHost = new System.Uri(UrlUtility::getUrl());

In the UrlUtility::getUrl() method the following method is executed:

SessionContext serverContext = SessionContext::Get_Current();

The workaround is to use EnvironmentFactory::GetApplicationEnvironment() method instead, in order to read its Infrastructure.HostUrl:

IApplicationEnvironment env = EnvironmentFactory::GetApplicationEnvironment();
str currentUrl = env.Infrastructure.HostUrl;

The whole method looks like the following:

Leave a Reply

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

*

Docentric respects your privacy. Learn how your comment data is processed >>

Docentric respects your privacy. Learn how your comment data is processed >>