diff --git a/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.html b/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.html
index 2317d63dcf780d365c4ed327c67861c23d2cd791..d4dea898462d03ccf86bf26dc42df986bbe16c2e 100644
--- a/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.html
+++ b/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.html
@@ -27,7 +27,6 @@
            readonly>
   </mat-form-field>
   <mat-checkbox formControlName="sharingEnabled"
-                [disabled]="disableShareDocument"
                 matTooltip="{{ 'document.configuration.panel.tooltip.sharing.enabled' | translate }}"
                 id="sharingEnabled_id">
     {{ "document.configuration.panel.label.sharing.enabled" | translate }}
@@ -37,8 +36,8 @@
     <mat-toolbar-row class="smp-toolbar-row">
       <button mat-raised-button
               mat-flat-button color="primary"
-              [disabled]="disableShowReferenceDialogButton"
               (click)="onShowSearchDialogClicked()"
+              [disabled]="hasReferenceDocument"
       >{{ "document.configuration.panel.button.reference.select" | translate }}
       </button>
 
diff --git a/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.ts b/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.ts
index 69a6048e37b85d8427f65938460c52647f5c85e7..941395a28b27a268a27862c2212c3f75a415de57 100644
--- a/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.ts
+++ b/smp-angular/src/app/common/panels/document-edit-panel/document-configuration-panel/document-configuration-panel.component.ts
@@ -120,6 +120,7 @@ export class DocumentConfigurationPanelComponent implements OnInit, AfterViewIni
    */
   writeValue(data: DocumentConfigurationRo): void {
     this.documentConfiguration = data;
+    this.updateShareCheckboxStatus();
   }
 
   ngAfterViewInit() {
@@ -189,16 +190,9 @@ export class DocumentConfigurationPanelComponent implements OnInit, AfterViewIni
     return docConf;
   }
 
-  get disableShowReferenceDialogButton(): boolean {
-    return this.hasReferenceDocument  || this.documentConfigurationForm.controls['sharingEnabled'].value;
-  }
-
-  get disableShareDocument(): boolean {
-    return this.hasReferenceDocument && !this.documentConfigurationForm.controls['sharingEnabled'].value;
-  }
-
   get hasReferenceDocument(): boolean {
-    return !!this.documentConfigurationForm.controls['referenceDocumentId']?.value;
+    let val = this.documentConfigurationForm.controls['referenceDocumentId']?.value;
+    return !!val && val.length > 0;
   }
 
   get hasReferenceDocumentUrl(): boolean {
@@ -226,14 +220,26 @@ export class DocumentConfigurationPanelComponent implements OnInit, AfterViewIni
         this.documentConfigurationForm.controls['referenceDocumentName'].setValue(value.documentName);
         this.documentConfigurationForm.controls['referenceDocumentUrl'].setValue(value.referenceUrl);
         this.onChangeCallback(this.documentConfiguration);
+        this.updateShareCheckboxStatus();
       }
     });
   }
 
+  updateShareCheckboxStatus() {
+    if (this.hasReferenceDocument) {
+      this.documentConfigurationForm.controls['sharingEnabled'].setValue(false);
+      this.documentConfigurationForm.controls['sharingEnabled'].disable();
+    } else
+    {
+      this.documentConfigurationForm.controls['sharingEnabled'].enable();
+    }
+  }
+
   onClearReferenceDocument(): void {
     this.documentConfigurationForm.controls['referenceDocumentId'].setValue("");
     this.documentConfigurationForm.controls['referenceDocumentName'].setValue("");
     this.documentConfigurationForm.controls['referenceDocumentUrl'].setValue("");
+    this.updateShareCheckboxStatus()
   }
 
 }
diff --git a/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.html b/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.html
index b2099be79173de046911a6b2cbc6a3cad25fac8c..226040b802b717520cd0a5e982d87f48cb850c5e 100644
--- a/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.html
+++ b/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.html
@@ -8,7 +8,7 @@
               mat-raised-button
               color="primary"
               matTooltip="{{ 'document.edit.panel.tooltip.version.new' | translate }}"
-              [disabled]="newVersionButtonDisabled"
+              [disabled]="newVersionButtonDisabled || showReference"
               (click)="onNewDocumentVersionButtonClicked()">
         <mat-icon>add_circle</mat-icon>
         <span>{{ "document.edit.panel.button.version.new" | translate }}</span>
@@ -50,7 +50,9 @@
       style="display:flex; overflow: auto;flex: 2;align-self: stretch; flex-direction: column;">
       <ng-container *ngIf="hasDocumentReference; else selectedDocumentVersionDataTemplate" >
         <div style="display:flex;  flex-direction: row;align-items: center;">
-        <mat-slide-toggle  (toggleChange)="toggleShowReference()" [checked]="showReference" style="display: inline-block;">Show reference</mat-slide-toggle>
+        <mat-slide-toggle
+          formControlName="toggleReferenceDocument"
+          (toggleChange)="toggleShowReference()" [checked]="showReference" style="display: inline-block;">Show reference</mat-slide-toggle>
         <ng-container *ngIf="showReference; else selectedDocumentVersionDataTemplate" >
           <div style="padding: 0 1em;display: flex;flex-direction: row;align-items: center;">
           <mat-form-field style="min-width: 250px"
@@ -58,8 +60,7 @@
                           appearance="fill">
             <mat-label>{{ "document.edit.panel.label.reference.name" | translate }}</mat-label>
             <input matInput id="reference-name_id"
-                   formControlName="documentReferenceName"
-                   readonly>
+                   formControlName="documentReferenceName">
           </mat-form-field>
           <a *ngIf="hasReferenceDocumentUrl"
              target="_blank"
diff --git a/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.ts b/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.ts
index 239001fb684f1538ab7c155e2c3723ab96dde381..b4351ef6f599de7750b944cf643a38b8ef656ab3 100644
--- a/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.ts
+++ b/smp-angular/src/app/common/panels/document-edit-panel/document-edit-panel.component.ts
@@ -99,11 +99,12 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
   readonly reviewAllowedStatusList: DocumentVersionsStatus[] = [DocumentVersionsStatus.DRAFT, DocumentVersionsStatus.REJECTED, DocumentVersionsStatus.RETIRED];
   readonly editableDocStatusList: DocumentVersionsStatus[] = [DocumentVersionsStatus.DRAFT, DocumentVersionsStatus.REJECTED, DocumentVersionsStatus.RETIRED];
   readonly publishableDocStatusList: DocumentVersionsStatus[] = [DocumentVersionsStatus.DRAFT, DocumentVersionsStatus.APPROVED, DocumentVersionsStatus.RETIRED];
+
   protected resource: ResourceRo;
   protected subresource: SubresourceRo;
   private reviewDocument: ReviewDocumentVersionRo;
-  private isResourceDocument:boolean = true;
-  protected toggleShowReferenceValue:boolean = true;
+
+  private isResourceDocument: boolean = true;
   private resetVersionOnNewDocument: number;
   _contextPath: string = location.pathname.substring(0, location.pathname.length - 3); // remove /ui s
 
@@ -183,7 +184,9 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
       } else {
         this.alertService.success(await lastValueFrom(this.translateService.get("document.edit.panel.success.generate")))
         this.documentForm.controls['payload'].setValue(doc.payload);
+        this.updateTextToEditor()
         this.documentForm.controls['payload'].markAsDirty();
+        this.documentForm.controls['editorText'].markAsDirty();
       }
     },
     error: (err: any) => {
@@ -216,7 +219,9 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
       'documentVersions': new FormControl({value: null}),
       'documentConfiguration': new FormControl({value: null}),
       "documentReferenceName": new FormControl({value: null}),
+      // additional fields
       "editorText": new FormControl({value: null}),
+      "toggleReferenceDocument": new FormControl({value: null}),
 
     });
 
@@ -278,6 +283,15 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
     } else {
       this.loadDocumentForVersion();
     }
+
+    this.documentForm.controls['editorText'].valueChanges.subscribe(() => {
+      // disable change back option
+      if(this.documentEditable && this.documentForm.controls['editorText'].dirty){
+        this.documentForm.controls['toggleReferenceDocument'].disable();
+      } else {
+        this.documentForm.controls['toggleReferenceDocument'].enable();
+      }
+    });
   }
 
 
@@ -305,32 +319,39 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
       if (this.documentVersionsExists && this.isNotReviewMode) {
         this.documentForm.controls['payloadVersion'].enable();
       }
-      this.updateEditorText()
+      this.updateTextToEditor()
+      if (this.isNewDocumentVersion) {
+        this.documentForm.markAsPristine();
+      }
     } else {
       this.documentForm.controls['name'].setValue("");
       this.documentForm.controls['currentResourceVersion'].setValue("");
       this.documentForm.controls['payloadVersion'].setValue("");
       this.documentForm.controls['payloadCreatedOn'].setValue("");
       this.documentForm.controls['payload'].setValue("");
+      this.documentForm.controls['editorText'].setValue("");
       this.documentForm.controls['referencePayload'].setValue("");
       this.documentForm.controls['properties'].setValue([]);
       this.documentForm.controls['documentVersionStatus'].setValue("");
       this.documentForm.controls['documentVersionEvents'].setValue([]);
       this.documentForm.controls['documentVersions'].setValue([]);
       this.documentForm.controls['documentConfiguration'].setValue(null);
+      this.documentForm.markAsPristine();
     }
-    this.documentForm.markAsPristine();
+
   }
 
   get document(): DocumentRo {
     let doc: DocumentRo = {...this._document};
-    if (this.documentForm.controls['payload'].dirty) {
-      doc.payload = this.documentForm.controls['payload'].value;
-      doc.payloadStatus = EntityStatus.UPDATED;
-    } else {
-      // no need to send payload if not changed
-      doc.payload = null;
-    }
+    if (this.showReference)
+      if (this.showReference && this.documentForm.controls['payload'].dirty) {
+        doc.payload = this.documentForm.controls['editorText'].value;
+        doc.payloadStatus = EntityStatus.UPDATED;
+
+      } else {
+        // no need to send payload if not changed
+        doc.payload = null;
+      }
 
     // set new properties
     doc.properties = this.documentForm.controls['properties'].value;
@@ -338,25 +359,28 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
     return doc;
   }
 
-  updateEditorText() {
-    if (this.showReference){
-      // set payload to editorText
+  /**
+   * When document is changed the method updates the editor text. If it contains a referemce and
+   * is showing then, reference payload is shown in the editor, otherwise the payload is shown.
+   */
+  updateTextToEditor() {
+    if (this.showReference) {
       this.documentForm.controls['payload'].setValue(this.documentForm.controls['editorText'].value);
       this.documentForm.controls['editorText'].setValue(this.documentForm.controls['referencePayload'].value);
       this.documentForm.controls['editorText'].disable();
-
       this.documentForm.controls['editorText'].markAsPristine();
     } else {
       this.documentForm.controls['editorText'].setValue(this.documentForm.controls['payload'].value);
       this.documentForm.controls['editorText'].markAsPristine();
       if (this.documentEditable) {
-        this.documentForm.controls['payload'].enable();
+        this.documentForm.controls['editorText'].enable();
       } else {
-        this.documentForm.controls['payload'].disable();
+        this.documentForm.controls['editorText'].disable();
       }
     }
   }
 
+
   onBackButtonClicked(): void {
     this.navigationService.navigateUp();
   }
@@ -376,17 +400,18 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
 
   resetChanges() {
     let currentVersion = this.isNewDocumentVersion ?
-      this.resetVersionOnNewDocument :  this._document?.payloadVersion;
+      this.resetVersionOnNewDocument : this._document?.payloadVersion;
     if (!currentVersion) {
       this.documentForm.controls['payload'].setValue("");
       this.documentForm.markAsPristine();
+      this.updateTextToEditor()
     } else {
       this.loadDocumentForVersion(currentVersion);
     }
   }
 
   get currentDocumentVersion(): number {
-    return this.isNotReviewMode? this.documentForm.controls['payloadVersion']?.value:
+    return this.isNotReviewMode ? this.documentForm.controls['payloadVersion']?.value :
       this.reviewDocument?.version;
   }
 
@@ -484,6 +509,7 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
       if (result) {
         let val = formRef.componentInstance.getExtensionXML();
         this.documentForm.controls['payload'].setValue(val);
+        this.updateTextToEditor()
         this.documentForm.controls['payload'].markAsDirty();
       }
     });
@@ -517,6 +543,7 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
         let smw: SubresourceWizardRo = formRef.componentInstance.getCurrent();
         this.documentForm.controls['payload'].setValue(smw.contentXML);
         this.documentForm.controls['payload'].markAsDirty();
+        this.updateTextToEditor();
       }
     });
   }
@@ -571,6 +598,7 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
     this.document = docRequest;
     this.documentForm.markAsDirty();
     this.documentForm.controls['payload'].markAsDirty();
+    this.documentForm.controls['editorText'].markAsDirty();
   }
 
   onSelectionDocumentVersionChanged(): void {
@@ -640,9 +668,10 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
   get isNewDocumentVersion(): boolean {
     return this._document?.payloadStatus === EntityStatus.NEW
   }
+
   get documentEditable(): boolean {
     let status = this.documentForm.controls['documentVersionStatus']?.value
-    return !!this.editableDocStatusList.find(i => i === status)
+    return !!this.editableDocStatusList.find(i => i === status) && !this.showReference;
   }
 
   get documentSubmitReviewAllowed(): boolean {
@@ -663,8 +692,7 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
   }
 
   toggleShowReference() {
-    this.toggleShowReferenceValue = !this.toggleShowReferenceValue;
-    this.updateEditorText();
+    this.updateTextToEditor();
   }
 
   get hasDocumentReference(): boolean {
@@ -672,7 +700,7 @@ export class DocumentEditPanelComponent implements BeforeLeaveGuard, OnInit {
   }
 
   get showReference(): boolean {
-    return this.hasDocumentReference && this.toggleShowReferenceValue;
+    return this.hasDocumentReference && this.documentForm.controls['toggleReferenceDocument'].value;
   }
 
 
diff --git a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/DBSearchReferenceDocumentVersionToSearchReferenceDocumentROConverter.java b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/DBSearchReferenceDocumentVersionToSearchReferenceDocumentROConverter.java
index 10b6b349a9fb2350a5cdd5d7e373d95111fccff5..e221c37a29ea6337b415b6cbff6b6ebb71e3c7a7 100644
--- a/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/DBSearchReferenceDocumentVersionToSearchReferenceDocumentROConverter.java
+++ b/smp-server-library/src/main/java/eu/europa/ec/edelivery/smp/conversion/DBSearchReferenceDocumentVersionToSearchReferenceDocumentROConverter.java
@@ -69,18 +69,29 @@ public class DBSearchReferenceDocumentVersionToSearchReferenceDocumentROConverte
         return target;
     }
 
+
+    /**
+     * Method returns  partial reference URL for given reference document
+     * @param source reference document
+     * @return partial reference URL
+     */
     private String getReferenceUrl(DBSearchReferenceDocumentMapping source) {
 
         String ctx = URL_SEPARATOR + getUrlPart(source.getDomainCode()) + getUrlPart(source.getResourceDefUrlSegment());
-        ctx += identifierService.urlEncodedFormatParticipant(source.getDomainCode(), new Identifier(source.getResourceScheme(), source.getResourceValue()));
+        ctx += identifierService.urlEncodedFormatParticipant(source.getDomainCode(), new Identifier(source.getResourceValue(), source.getResourceScheme()));
 
         if (source.getReferenceType() == DocumentReferenceType.SUBRESOURCE) {
             ctx += URL_SEPARATOR + getUrlPart(source.getSubresourceDefUrlSegment())
-                    + identifierService.urlEncodedFormatDocument(source.getDomainCode(), new Identifier(source.getSubresourceScheme(), source.getSubresourceValue()));
+                    + identifierService.urlEncodedFormatDocument(source.getDomainCode(), new Identifier(source.getSubresourceValue(), source.getSubresourceScheme()));
         }
         return ctx;
     }
 
+    /**
+     * Method returns URL part for given value
+     * @param value the part of URL
+     * @return trimmed value which ends with URL_SEPARATOR or empty string
+     */
     private String getUrlPart(String value) {
         return StringUtils.isBlank(value) ? "" : value + URL_SEPARATOR;
     }