Configure document management

This article explains how to configure document management (document handling) so that it stores file attachments and notes for records. It includes information about the concepts and features that are involved in this functionality.

To learn more about document management, watch the short Document Management video.

Configure document types

Document types are used to categorize the documents that you attach to records or the templates that you create. Each document type can be stored in a unique location.

A default set of document types is provided. You can use these document types to categorize an attachment as a file, image, note, or URL. The File and Image default document types are configured to use Azure storage as the location.

To create a new document type, follow these steps.

  1. Go to the Document types page.
  2. Select New.
  3. In the Type field, enter a short name for the new document type, such as SharePoint or HR Docs.
  4. In the Name field, enter a longer name, such as SharePoint files or HR Docs.
  5. In the Class field, specify a class to define the behavior for the document type:
  6. If you specified Attach file in the Class field, in the Location field, specify the storage mechanism to use.
  7. If you specified SharePoint in the Location field, specify the Microsoft SharePoint address in the SharePoint Address field by selecting the Edit button (pencil symbol) and using the Folder selection dialog box.

Configure SharePoint storage

SharePoint Online is a supported storage location for attachments.

One-time registration process

In Dynamics 365 finance and operations version 10.0.40 and later, when the SharePoint user authentication feature is enabled, your organization needs to perform a one-time setup to use the SharePoint integration for non-interactive batch scenarios. This is because the Microsoft-managed high-trust connection between the finance and operations environment and SharePoint has been deprecated.

With this updated SharePoint authentication mechanism, batch connections utilize application access. As this access is not granted by default for tenants, an Entra ID tenant administrator needs to be manually grant access one time for the tenant. This can be done by running the following PowerShell commands to provide the required application consent for finance and operations batch scenarios to connect to SharePoint.

 Import-Module Microsoft.Graph # The parameter for TenantId needs to be changed Connect-MgGraph -TenantId microsoft.onmicrosoft.com -Scopes 'Application.ReadWrite.All' # These AppIds do not change as they are the first party application IDs $erpServicePrincipal = Get-MgServicePrincipal -Filter "AppId eq '00000015-0000-0000-c000-000000000000'" $sharePointServicePrincipal = Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0ff1-ce00-000000000000'" $spAppRole = $sharePointServicePrincipal.AppRoles | where # Assign the SharePoint 'Sites.ReadWrite.All' permission to the Microsoft Dynamics 365 finance and operations application New-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $erpServicePrincipal.Id -PrincipalId $erpServicePrincipal.Id -ResourceId $sharePointServicePrincipal.Id -AppRoleId $spAppRole.Id 

Interactive connections will utilize the logged-in user's context.

Setting up SharePoint inside your finance and operations environment

To configure SharePoint storage, follow these steps.

  1. Go to the Document management parameters page.
  2. On the SharePoint tab, in the Default SharePoint server field, review the host name that was automatically detected for the SharePoint site, such as contosoax7.sharepoint.com. Typically, the SharePoint host name is in the form tenantname.sharepoint.com, and accounts on that tenant are in the form user1@tenantname.onmicrosoft.com . Typically, if no default SharePoint server is specified, either there's no SharePoint site for the tenant, or a valid Microsoft 365 license isn't associated with the current user (the admin).
  3. Optional: Test the SharePoint connection
  4. Optional: Select Open SharePoint to open the specified SharePoint host name in a browser. This action doesn't verify security. It just opens the SharePoint path on a browser tab for easy exploration.
  5. Optional: On the General tab, turn on Open attachments in new window. For more information, see the Other configuration section later in this article.

To use SharePoint storage, set the Location field for a document type to SharePoint. Then, in the SharePoint Address field, enter a valid SharePoint address.

Troubleshooting SharePoint communication

SharePoint communication works for the current user only if the following conditions are met:

If documents that are stored in SharePoint aren't opened or don't appear in preview, follow these steps to troubleshoot the issue.

  1. Verify that the Admin account has an associated email account. You can verify or change the associated email account on the User page. If an associated email account isn't set up, you must add the email account and provider via the OData Excel add-in. By default, the email address isn't present in the Excel design. The user must edit the Excel design, add all fields, apply the change, and refresh. You can then update the Admin account.
  2. After the Admin account has an associated email account, sign in to Dynamics 365 as the admin.
  3. Open an attachment that's stored in SharePoint.
  4. Sign in by using a different user account that has read access to the attachments page and the configured SharePoint folder. Verify that this user account can open and preview the attachment.

Configure file types

By modifying the list of file extensions that are allowed, you can control the types of files that users can attach to records.

To specify file types, follow these steps.

  1. Go to the Document management parameters page.
  2. On the File types tab, review the default file types.
  3. Remove any file types that users shouldn't be able to attach to records. Add any file types that users should be able to attach to records.

Configure document preview

The attachments preview uses the Web app Open Platform Interface (WOPI) that Office Online Server provides. On the Document management parameters page, on the General tab, in the Office Web Apps Server field, specify the Office Online Server instance to use for attachment previews. The default value is https://onenote.officeapps.live.com , which points to the cloud-based WOPI server.

For the following situations, you must adjust the Office Web Apps Server value:

For a Dynamics 365 Finance + Operations (on-premises) environment

The default cloud-based WOPI server in Finance + Operations (on-premises) can't read the attachment file to provide a preview. If previews are required, you must install an on-premises Office Online Server instance and configure it inside the environment. Set the Office Web Apps Server field to the host name of the installed Office Online Server instance, and then select Save.

If previews aren't required, set the Office Web Apps Server field to https://localhost . The preview then shows the message "No preview available" instead of an error message.

Document preview (WOPI) doesn't work in environments where an IP safe list is enabled

Document preview (WOPI) doesn't work in environments where an IP safe list is enabled, because the WOPI service that provides the preview can't connect back to the file service to retrieve the file for rendering.

Other configuration

Here are some other configuration options to consider:

Accessing document management attachments

Document management appears to users as the Attach button at the top of most pages that contain data. When you select the Attach button (or when you use the corresponding keyboard shortcut, Ctrl+Shift+A), the Attachments page is opened in the context of the data source of the control that's currently selected on the page. This page shows all the attachments that are related to the corresponding data source.

The Attach button also shows a count of the attachments for the currently selected record. Therefore, you can determine whether there are attachments for the current record without having to open the Attachments page. The button shows exact counts for zero through nine attachments. If there are more than nine attachments, the button shows 9+ as the count. In this way, the performance impact and visual noise that exact larger counts might cause are reduced.

Document attachment history

As of version 10.0.16/Platform update 40, a history mechanism is available for record attachments. Therefore, your organization can maintain an audit of actions that are related to individual attachments. You can see when an attachment was created, marked for pending deletion, restored, deleted, or moved. You can also see who performed the action. Attachment history isn't maintained until version 10.0.16/Platform update 40. Therefore, any actions that were performed on attachments in earlier versions aren't available.

Configuration of document attachment history

To enable (or disable) document attachment history, go to Document management parameters > General > History > Enable document history. The default setting of the Number of days to retain history field is 180 days, but you can change it as you require.

Viewing an attachment's history

There are two entry points for viewing the history of a record attachment:

Attachment recovery

In Platform update 29, an attachment recovery feature was added. This feature provides a recycle bin for record attachments, so that they can be recovered within a configured period.

Configuration of attachment recovery

To enable attachment recovery, go to Document management parameters > General > Deferred deletion > Deferred deletion enabled. The default setting for the Number of days to defer deletion field is 30 days, but you can change it as you require. If the Number of days to defer deletion value is 0 (zero), deleted attachments are recoverable for an indefinite period.

After you enable attachment recovery, a batch job that's named Scans for deleted references which have reached the end of their retention period is created. This batch job uses the Number of days to defer deletion value to determine how long a deleted attachment should be retained, based on the Deleted date and time value.

Deleting attachments when attachment recovery is active

When a user deletes an attachment, a notification is added to the Message Center to confirm the deletion. The notification also provides an option that lets you undo the deletion if it was unintended.

Table extension support is built in. Therefore, any extension or custom field values on the DocuRef or DocuValue table are retained to enable their recovery.

Recovering attachments

When attachment recovery is enabled, attachments can be recovered in one of three ways:

Scanning attachments for viruses and malicious code

When you work with attachments, you might want to scan the files for viruses and malicious code. Therefore, in version 10.0.12 and later, extension points are available so that customers can integrate with the file scanning software of their choice when they work with attachments. A similar extension point is also available for file upload. For more information, see File upload control.

Out of the box, finance and operations apps don't scan files for viruses and malicious code, and we don't recommend specific software for file scanning. Instead, customers are responsible for choosing their own file scanning software, and for adding the appropriate code to the delegate handlers so that they can use the software or service of their choice to scan files.

The Docu class exposes the following two delegates. Handlers can be implemented for these delegates for document scanning purposes:

Implementation details

The following example of the ScanDocuments class shows boilerplate code for the two handlers. For general information about how to implement handlers for delegates, see EventHandlerResult classes in request or response scenarios.

public final class ScanDocuments < [SubscribesTo(classStr(Docu), staticDelegateStr(Docu, delegateScanDocument))] public static void Docu_delegateScanDocument(DocuRef _docuRef, EventHandlerRejectResult _validationResult) < if (!ScanDocuments::scanDocument(_docuRef)) < _validationResult.reject(); >> [SubscribesTo(classStr(Docu), staticDelegateStr(Docu, delegateScanDeletedDocument))] public static void Docu_delegateScanDeletedDocument(DocuDeletedRef _docuDeletedRef, EventHandlerRejectResult _validationResult) < if (!ScanDocuments::scanDeletedDocument(_docuDeletedRef)) < _validationResult.reject(); >> private static boolean scanDocument(DocuRef _docuRef) < /* Custom implementation required for connecting to a scanning service If document scanning process found an issue, return false; otherwise, return true; */ return true; >private static boolean scanDeletedDocument(DocuDeletedRef _docuDeletedRef) < /* Custom implementation required for connecting to a scanning service If document scanning process found an issue, return false; otherwise, return true; */ return true; >> 

[Developer] Specifying valid content types when attaching documents programmatically

The following APIs from the DocumentManagement class let developers specify the file content type (MIME type) of the file that's being attached:

If the file content type isn't specified correctly, the attached document might not behave as expected. Therefore, if you use these APIs, you should consider one of the following courses of action: