From 37a46707967fa6377188f7ed7d5837616825929b Mon Sep 17 00:00:00 2001
From: "S.Listl" <S.Listl@SLISTL.aditosoftware.local>
Date: Thu, 30 Jan 2020 10:08:51 +0100
Subject: [PATCH] Bulkmail upload bugfix

---
 .../BulkMail_entity/entityfields/content/contentTypeProcess.js  | 2 +-
 .../BulkMail_entity/entityfields/content/displayValueProcess.js | 2 +-
 entity/BulkMail_entity/entityfields/content/stateProcess.js     | 2 +-
 entity/BulkMail_entity/entityfields/name/valueProcess.js        | 2 +-
 entity/BulkMail_entity/recordcontainers/db/onDBInsert.js        | 2 +-
 entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js        | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js b/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js
index 49308df2f63..8f43fce9661 100644
--- a/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js
+++ b/entity/BulkMail_entity/entityfields/content/contentTypeProcess.js
@@ -5,6 +5,6 @@ import("Document_lib");
 import("system.vars");
 import("DocumentTemplate_lib");
 
-result.string(vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT
+result.string(vars.exists("$context.currentTemplateType") && vars.get("$context.currentTemplateType") == DocumentTemplate.types.TXT
     ? "LONG_TEXT" 
     : "HTML");
\ No newline at end of file
diff --git a/entity/BulkMail_entity/entityfields/content/displayValueProcess.js b/entity/BulkMail_entity/entityfields/content/displayValueProcess.js
index eb9e6ef7f14..577d092a84b 100644
--- a/entity/BulkMail_entity/entityfields/content/displayValueProcess.js
+++ b/entity/BulkMail_entity/entityfields/content/displayValueProcess.js
@@ -8,7 +8,7 @@ import("system.neon");
 import("DocumentTemplate_lib");
 
 // if this was done for every row, like in a lookup, the performance would be very bad
-if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET) 
+if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET && vars.get("$field.content")) 
 {
     var template = new DocumentTemplate(util.encodeBase64String(vars.get("$field.content")), vars.get("$context.currentTemplateType"), undefined, true)
     
diff --git a/entity/BulkMail_entity/entityfields/content/stateProcess.js b/entity/BulkMail_entity/entityfields/content/stateProcess.js
index d48b2b6f007..1debaa69264 100644
--- a/entity/BulkMail_entity/entityfields/content/stateProcess.js
+++ b/entity/BulkMail_entity/entityfields/content/stateProcess.js
@@ -4,7 +4,7 @@ import("system.neon");
 import("DocumentTemplate_lib");
 
 // in edit mode
-if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW && 
+if (vars.get("$sys.recordstate") != neon.OPERATINGSTATE_VIEW && vars.exists("$context.currentTemplateType") &&
     (vars.get("$context.currentTemplateType") == DocumentTemplate.types.EML
       || vars.get("$context.currentTemplateType") == DocumentTemplate.types.HTML)) // TODO: invisible for html as there are problems with images which are removed by the html-editor
 {
diff --git a/entity/BulkMail_entity/entityfields/name/valueProcess.js b/entity/BulkMail_entity/entityfields/name/valueProcess.js
index 829431cf9f1..adb0f3d6b2f 100644
--- a/entity/BulkMail_entity/entityfields/name/valueProcess.js
+++ b/entity/BulkMail_entity/entityfields/name/valueProcess.js
@@ -12,7 +12,7 @@ if (!vars.get("$this.value") && vars.get("$sys.recordstate") == neon.OPERATINGST
         var filename = DocumentUtil.getFilenameFromUpload(upload);
         result.string(filename.split(".")[0]);
     }
-    else
+    else if (vars.get("$field.DOCUMENTTEMPLATE_ID"))
     {
         var conf = entities.createConfigForLoadingRows();
         conf.entity("DocumentTemplate_entity")
diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js
index a7026f98968..e8fcb2f9e54 100644
--- a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js
+++ b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js
@@ -20,7 +20,7 @@ var bulkMailName = rowdata["BULKMAIL.NAME"];
 
 var template = DocumentTemplate.getSelectedTemplate(templateId, new FileUpload(bindata), content, DocumentTemplate.types.HTML);
 
-if (template && template.content)
+if (template && template.content && BulkMailUtils.isValidTemplateType(template.type))
 {
     if (!template.filename)
         template.filename = bulkMailName + ".html";
diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
index 3d3fb010196..258fff593db 100644
--- a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
+++ b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js
@@ -20,7 +20,7 @@ var bulkMailName = rowdata["BULKMAIL.NAME"];
 
 var template = DocumentTemplate.getSelectedTemplate(templateId, new FileUpload(bindata), content, DocumentTemplate.types.HTML);
 
-if (template && template.content)
+if (template && template.content && BulkMailUtils.isValidTemplateType(template.type))
 {
     if (!template.filename)
         template.filename = bulkMailName + ".html";
-- 
GitLab