diff --git a/src/app/template/controllers/TemplateController.php b/src/app/template/controllers/TemplateController.php
index 4c858173ae9a55c4ea3588d8e9c1c14c8e7ec7c1..3e39844faa28401c11ecdeecac6916cf48b7ab0d 100644
--- a/src/app/template/controllers/TemplateController.php
+++ b/src/app/template/controllers/TemplateController.php
@@ -61,7 +61,6 @@ class TemplateController
                 $entities[$key]['selected'] = true;
             }
         }
-        $template['entities'] = $entities;
 
         $attachmentModelsTmp = AttachmentModel::getAttachmentsTypesByXML();
         $attachmentTypes = [];
@@ -73,10 +72,11 @@ class TemplateController
         }
 
         return $response->withJson([
-            'template'        => $template,
-            'templatesModels' => TemplateController::getModels(),
-            'attachmentTypes' => $attachmentTypes,
-            'datasources'     => TemplateModel::getDatasources()
+            'template'          => $template,
+            'templatesModels'   => TemplateController::getModels(),
+            'attachmentTypes'   => $attachmentTypes,
+            'datasources'       => TemplateModel::getDatasources(),
+            'entities'          => $entities
         ]);
     }
 
@@ -92,21 +92,25 @@ class TemplateController
         }
 
         if ($data['template_type'] == 'OFFICE') {
-            $explodeStyle = explode(':', $data['template_style']);
-            $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]);
-            $storeResult = DocserverController::storeResourceOnDocServer([
-                'collId'            => 'templates',
-                'docserverTypeId'   => 'TEMPLATES',
-                'fileInfos'         => [
-                    'tmpDir'            => CoreConfigModel::getTmpPath(),
-                    'tmpFileName'       => $fileOnTmp,
-                ]
-            ]);
-            if (!empty($storeResult['errors'])) {
-                return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]);
+            if (!empty($data['userUniqueId'])) {
+                $explodeStyle = explode(':', $data['template_style']);
+                $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]);
+                $storeResult = DocserverController::storeResourceOnDocServer([
+                    'collId'            => 'templates',
+                    'docserverTypeId'   => 'TEMPLATES',
+                    'fileInfos'         => [
+                        'tmpDir'            => CoreConfigModel::getTmpPath(),
+                        'tmpFileName'       => $fileOnTmp,
+                    ]
+                ]);
+                if (!empty($storeResult['errors'])) {
+                    return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]);
+                }
+                $data['template_path'] = $storeResult['destination_dir'];
+                $data['template_file_name'] = $storeResult['file_destination_name'];
+            } else {
+                return $response->withStatus(400)->withJson(['errors' => 'Template file is missing']);
             }
-            $data['template_path'] = $storeResult['destination_dir'];
-            $data['template_file_name'] = $storeResult['file_destination_name'];
         }
 
         $id = TemplateModel::create($data);
@@ -134,15 +138,7 @@ class TemplateController
         }
 
         $data = $request->getParams();
-
-        $check = Validator::stringType()->notEmpty()->validate($data['template_label']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['template_comment']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['template_type']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['template_datasource']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['template_target']);
-        $check = $check && Validator::stringType()->notEmpty()->validate($data['template_attachment_type']);
-        if (!$check) {
+        if (!TemplateController::checkData(['data' => $data])) {
             return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
         }
 
@@ -151,6 +147,26 @@ class TemplateController
             return $response->withStatus(400)->withJson(['errors' => 'Template does not exist']);
         }
 
+        if ($data['template_type'] == 'OFFICE') {
+            if (!empty($data['userUniqueId'])) {
+                $explodeStyle = explode(':', $data['template_style']);
+                $fileOnTmp = "tmp_file_{$GLOBALS['userId']}_{$data['userUniqueId']}." . strtolower($explodeStyle[0]);
+                $storeResult = DocserverController::storeResourceOnDocServer([
+                    'collId'            => 'templates',
+                    'docserverTypeId'   => 'TEMPLATES',
+                    'fileInfos'         => [
+                        'tmpDir'            => CoreConfigModel::getTmpPath(),
+                        'tmpFileName'       => $fileOnTmp,
+                    ]
+                ]);
+                if (!empty($storeResult['errors'])) {
+                    return $response->withStatus(500)->withJson(['errors' => '[storeResource] ' . $storeResult['errors']]);
+                }
+                $data['template_path'] = $storeResult['destination_dir'];
+                $data['template_file_name'] = $storeResult['file_destination_name'];
+            }
+        }
+
         if (!empty($data['entities']) && is_array($data['entities'])) {
             TemplateAssociationModel::delete(['where' => ['template_id = ?'], 'data' => [$aArgs['id']]]);
             foreach ($data['entities'] as $entity) {
@@ -338,7 +354,6 @@ class TemplateController
         if ($data['template_type'] == 'HTML' || $data['template_type'] == 'TXT') {
             $check = $check && Validator::stringType()->notEmpty()->validate($data['template_content']);
         } else {
-            $check = $check && Validator::stringType()->notEmpty()->validate($data['userUniqueId']);
             $check = $check && Validator::stringType()->notEmpty()->validate($data['template_style']);
         }