diff --git a/src/System Application/App/Document Sharing/app.json b/src/System Application/App/Document Sharing/app.json
index d077688842..3f3d6f47d9 100644
--- a/src/System Application/App/Document Sharing/app.json
+++ b/src/System Application/App/Document Sharing/app.json
@@ -47,7 +47,7 @@
"idRanges": [
{
"from": 9560,
- "to": 9562
+ "to": 9563
}
],
"contextSensitiveHelpUrl": "https://learn.microsoft.com/dynamics365/business-central/"
diff --git a/src/System Application/App/Document Sharing/src/DocumentSharing.Table.al b/src/System Application/App/Document Sharing/src/DocumentSharing.Table.al
index 9c3c6c07d0..b4fa4be09e 100644
--- a/src/System Application/App/Document Sharing/src/DocumentSharing.Table.al
+++ b/src/System Application/App/Document Sharing/src/DocumentSharing.Table.al
@@ -121,6 +121,15 @@ table 9560 "Document Sharing"
DataClassification = SystemMetadata;
InitValue = Ask;
}
+
+ ///
+ /// Specifies the state of the document sharing operation.
+ ///
+ field(13; State; Enum "Document Sharing State")
+ {
+ DataClassification = SystemMetadata;
+ InitValue = Success;
+ }
}
keys
diff --git a/src/System Application/App/Document Sharing/src/DocumentSharingImpl.Codeunit.al b/src/System Application/App/Document Sharing/src/DocumentSharingImpl.Codeunit.al
index e746262114..7e95edac40 100644
--- a/src/System Application/App/Document Sharing/src/DocumentSharingImpl.Codeunit.al
+++ b/src/System Application/App/Document Sharing/src/DocumentSharingImpl.Codeunit.al
@@ -134,7 +134,8 @@ codeunit 9561 "Document Sharing Impl."
Handled := false;
Sleep(2000); // This sleep is to ensure the OneDrive clears the lock on the file after the user saves and closes.
DocumentSharingCodeunit.OnGetFileContents(DocumentSharing, Handled);
- end;
+ end else
+ DocumentSharing.State := DocumentSharing.State::Cancelled;
Handled := false;
DocumentSharingCodeunit.OnDeleteDocument(DocumentSharing, Handled);
diff --git a/src/System Application/App/Document Sharing/src/DocumentSharingState.Enum.al b/src/System Application/App/Document Sharing/src/DocumentSharingState.Enum.al
new file mode 100644
index 0000000000..4400237e5a
--- /dev/null
+++ b/src/System Application/App/Document Sharing/src/DocumentSharingState.Enum.al
@@ -0,0 +1,30 @@
+// ------------------------------------------------------------------------------------------------
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License. See License.txt in the project root for license information.
+// ------------------------------------------------------------------------------------------------
+
+namespace System.Integration;
+
+///
+/// The result of the sharing operation.
+///
+enum 9563 "Document Sharing State"
+{
+ Extensible = false;
+
+ ///
+ /// Operation completed successfully.
+ ///
+ value(0; Success)
+ {
+ Caption = 'Success';
+ }
+
+ ///
+ /// Operation cancelled.
+ ///
+ value(1; Cancelled)
+ {
+ Caption = 'Cancelled';
+ }
+}
\ No newline at end of file
diff --git a/src/System Application/App/Word Templates/src/WordTemplateImpl.Codeunit.al b/src/System Application/App/Word Templates/src/WordTemplateImpl.Codeunit.al
index 40a4811e2d..aca6724acb 100644
--- a/src/System Application/App/Word Templates/src/WordTemplateImpl.Codeunit.al
+++ b/src/System Application/App/Word Templates/src/WordTemplateImpl.Codeunit.al
@@ -609,6 +609,10 @@ codeunit 9988 "Word Template Impl."
TempDocumentSharing.Insert();
DocumentSharing.Share(TempDocumentSharing);
+
+ if TempDocumentSharing.State = TempDocumentSharing.State::Cancelled then
+ Error('');
+
ResultTempBlob.CreateOutStream(OutStream, TextEncoding::UTF8);
TempDocumentSharing.Data.CreateInStream(InStream, TextEncoding::UTF8);
CopyStream(OutStream, InStream);