From 9b6f2b3bf52b961f58b655275039e4201d2ba664 Mon Sep 17 00:00:00 2001
From: Benjamin Ulrich <b.ulrich@adito.de>
Date: Thu, 20 Feb 2020 10:14:26 +0000
Subject: [PATCH] [Projekt: Entwicklung - Neon][TicketNr.: 1051275][Serienbrief
 kann nicht erzeugt werden]

---
 .../recordcontainers/db/onDBInsert.js                |  2 +-
 process/Bulkmail_lib/process.js                      | 12 +++++++++---
 process/DocumentTemplate_lib/process.js              | 11 +++++++++--
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/entity/SerialLetter_entity/recordcontainers/db/onDBInsert.js b/entity/SerialLetter_entity/recordcontainers/db/onDBInsert.js
index 8b5fdc99a8..b22db28618 100644
--- a/entity/SerialLetter_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/SerialLetter_entity/recordcontainers/db/onDBInsert.js
@@ -14,5 +14,5 @@ var template = DocumentTemplate.fromUpload(bindata);
 
 if (template.content)
 {
-    SingleBinaryUtils.insert("SERIALLETTER", "DOCUMENT", letterId, template.content, template.filename, "");
+    SingleBinaryUtils.insert("SERIALLETTER", "SERIALLETTERFILE", letterId, template.content, template.filename, "");
 }
\ No newline at end of file
diff --git a/process/Bulkmail_lib/process.js b/process/Bulkmail_lib/process.js
index ed01a6c323..c1fe514fe5 100644
--- a/process/Bulkmail_lib/process.js
+++ b/process/Bulkmail_lib/process.js
@@ -431,12 +431,18 @@ SerialLetterUtils.buildSerialLetter = function (pSerialLetterId, pRecipientIds)
         contactIdsSelect.and("LETTERRECIPIENT.LETTERRECIPIENTID", pRecipientIds, SqlBuilder.IN());
 
     var contactIds = contactIdsSelect.table();
-    
+    if(template != null){
     return {
-        content : template.getSerialLetterByContactIds(contactIds),
+        content : template.content,
         filename : template.filename,
         title : title
-    };
+    };}
+    else{
+        return{
+            title : title
+}
+
+    }
 }
 
 /**
diff --git a/process/DocumentTemplate_lib/process.js b/process/DocumentTemplate_lib/process.js
index 7630a1c2fe..79562b7f64 100644
--- a/process/DocumentTemplate_lib/process.js
+++ b/process/DocumentTemplate_lib/process.js
@@ -256,7 +256,13 @@ DocumentTemplate.loadTemplate = function (pAssignmentRowId, pAssignmentTable, pR
         var template = DocumentTemplateUtils.getTemplate(templateId, pResolveSubtemplates);
         if (template == null)
         {
-            question.showMessage(translate.text("File from this template could not be found anymore. Please go to the template and upload a new file."), question.ERROR, translate.text("Error"));
+            if(vars.getString("$sys.isserver") == "true")
+                throw new Error("loadTemplate: File from this template could not be found anymore. "
+                                + "Please go to the template and upload a new file. TemplateID: '" + templateId + "'")
+            else
+                question.showMessage(translate.text("File from this template could not be found anymore. "
+                                + "Please go to the template and upload a new file."), question.ERROR, translate.text("Error"));
+            
             return null;
         }
     }
@@ -269,7 +275,8 @@ DocumentTemplate.loadTemplate = function (pAssignmentRowId, pAssignmentTable, pR
     var mimeType = templateDocument[0][db.BINARY_MIMETYPE];
     var type = DocumentTemplate.types.fromBinaryMetadata(templateDocument[0]);
     
-    if (pResolveSubtemplates == undefined) pResolveSubtemplates = true;
+    if (pResolveSubtemplates == undefined)
+        pResolveSubtemplates = true;
     
     return new DocumentTemplate(db.getBinaryContent(binaryId, alias), type, filename, pResolveSubtemplates, templateId, mimeType);
 }
-- 
GitLab