diff --git a/entity/BulkMail_entity/entityfields/documenttemplate_id/onValueChange.js b/entity/BulkMail_entity/entityfields/documenttemplate_id/onValueChange.js index 29a05d9cfbd66e9856c62942b74a976cecc696ec..6673df6b950ad89ff126d3665d655f06da0b38d8 100644 --- a/entity/BulkMail_entity/entityfields/documenttemplate_id/onValueChange.js +++ b/entity/BulkMail_entity/entityfields/documenttemplate_id/onValueChange.js @@ -16,7 +16,7 @@ if (vars.get("$sys.recordstate") == neon.OPERATINGSTATE_NEW || vars.get("$sys.re // TODO: load subject without loadTemplate again... maybe return with getTemplateContent() above? var templateId = vars.get("local.value"); var template = DocumentTemplate.loadTemplate(templateId, undefined, false); - if (template.type == DocumentTemplate.types.EML) + if (template && template.type == DocumentTemplate.types.EML) { let subject = mail.parseRFC(util.decodeBase64String(template.content))[mail.MAIL_SUBJECT]; neon.setFieldValue("$field.SUBJECT", subject); diff --git a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js index 93eba9d8b97d65649f4be9e3407c9dbb3544d914..06720b44b79338dc3252918df6a7664305a3c516 100644 --- a/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js +++ b/entity/BulkMail_entity/recordcontainers/db/onDBInsert.js @@ -19,7 +19,7 @@ var bulkMailName = rowdata["BULKMAIL.NAME"]; var template = DocumentTemplate.getSelectedTemplate(templateId, new FileUpload(bindata), content, DocumentTemplate.types.HTML); -if (template.content) +if (template && template.content) { 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 daf4625956496cec2e95fbd13c6fa66b6d674729..a22303d7142ddd58e56e5d27fb084cc8cf41bac3 100644 --- a/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js +++ b/entity/BulkMail_entity/recordcontainers/db/onDBUpdate.js @@ -19,7 +19,7 @@ var bulkMailName = rowdata["BULKMAIL.NAME"]; var template = DocumentTemplate.getSelectedTemplate(templateId, new FileUpload(bindata), content, DocumentTemplate.types.HTML); -if (template.content) +if (template && template.content) { if (!template.filename) template.filename = bulkMailName + ".html"; diff --git a/entity/Email_entity/entityfields/downloadtemplate/onActionProcess.js b/entity/Email_entity/entityfields/downloadtemplate/onActionProcess.js index c3e5346cbc704e5001d62ce42157a0a914c704e1..29a0e6a4ef57583673bf89a7fce3947200e3d690 100644 --- a/entity/Email_entity/entityfields/downloadtemplate/onActionProcess.js +++ b/entity/Email_entity/entityfields/downloadtemplate/onActionProcess.js @@ -4,5 +4,5 @@ import("system.vars"); var templateId = vars.get("$field.DOCUMENT_TEMPLATE"); var template = DocumentTemplate.loadTemplate(templateId, undefined, false); -if (template.content) +if (template && template.content) neon.download(template.content, template.filename); \ No newline at end of file diff --git a/entity/Letter_entity/entityfields/downloadtemplate/onActionProcess.js b/entity/Letter_entity/entityfields/downloadtemplate/onActionProcess.js index c3e5346cbc704e5001d62ce42157a0a914c704e1..29a0e6a4ef57583673bf89a7fce3947200e3d690 100644 --- a/entity/Letter_entity/entityfields/downloadtemplate/onActionProcess.js +++ b/entity/Letter_entity/entityfields/downloadtemplate/onActionProcess.js @@ -4,5 +4,5 @@ import("system.vars"); var templateId = vars.get("$field.DOCUMENT_TEMPLATE"); var template = DocumentTemplate.loadTemplate(templateId, undefined, false); -if (template.content) +if (template && template.content) neon.download(template.content, template.filename); \ No newline at end of file diff --git a/entity/Letter_entity/recordcontainers/jdito/onInsert.js b/entity/Letter_entity/recordcontainers/jdito/onInsert.js index 1f265afe9add14e01fe854a40f37466e00e52cd1..f82590e6fcb0df7f693a219f05579bddae213eda 100644 --- a/entity/Letter_entity/recordcontainers/jdito/onInsert.js +++ b/entity/Letter_entity/recordcontainers/jdito/onInsert.js @@ -8,16 +8,19 @@ import("DocumentTemplate_lib"); import("KeywordRegistry_basic"); var template = DocumentTemplate.getSelectedTemplate(vars.get("$field.DOCUMENT_TEMPLATE"), new FileUpload(vars.get("$field.bindata"))); -var contactId = vars.get("$param.ContactId_param"); -var content = template.getReplacedContentByContactId(contactId, true); -if (template.type) - neon.download(content, template.filename); - -var links = []; -if (contactId) +if (template) { - let context = ContactUtils.getContextByContactId(contactId); - links.push([context, contactId]); -} + var contactId = vars.get("$param.ContactId_param"); + var content = template.getReplacedContentByContactId(contactId, true); + if (template.type) + neon.download(content, template.filename); -ActivityUtils.createNewActivity(null, links, null, null, translate.text("Letter"), text.parseDocument(content), $KeywordRegistry.activityDirection$outgoing(), [[template.filename, content, false]]); + var links = []; + if (contactId) + { + let context = ContactUtils.getContextByContactId(contactId); + links.push([context, contactId]); + } + + ActivityUtils.createNewActivity(null, links, null, null, translate.text("Letter"), text.parseDocument(content), $KeywordRegistry.activityDirection$outgoing(), [[template.filename, content, false]]); +} diff --git a/entity/SerialLetter_entity/entityfields/downloadtemplate/onActionProcess.js b/entity/SerialLetter_entity/entityfields/downloadtemplate/onActionProcess.js index 518d384f3239345ec1115b58dd2afbd42a10d57e..c7cef2b830ba4e7aed42ff007b8be11394e170f6 100644 --- a/entity/SerialLetter_entity/entityfields/downloadtemplate/onActionProcess.js +++ b/entity/SerialLetter_entity/entityfields/downloadtemplate/onActionProcess.js @@ -3,5 +3,5 @@ import("system.vars"); import("DocumentTemplate_lib"); var template = DocumentTemplate.loadTemplate(vars.get("$field.DOCUMENTTEMPLATE_ID"), undefined, false); -if (template.type) +if (template && template.type) neon.download(template.content, template.filename); \ No newline at end of file diff --git a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod index cce8452878d1ddc5327114f21d486bcbe38ea8cf..2482b082163a75c53bcd336236bf192e067fbba1 100644 --- a/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod +++ b/language/_____LANGUAGE_EXTRA/_____LANGUAGE_EXTRA.aod @@ -5909,6 +5909,12 @@ <entry> <key>SqlBuilder: invalid value-type for pFieldOrCond. It can be a fully qualified SqlBuilder (e.g. select, from, ... have to be set) or an jdito-prepared-statement array</key> </entry> + <entry> + <key>Error</key> + </entry> + <entry> + <key>File from this template could not be found anymore. Please go to the template and upload a new file.</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> <sqlModels> diff --git a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod index b11ee95e61021efb8eaf52ee75f6a9b27ab4af28..3ae5c657ab282af50e2d7418ad55af58311fe6db 100644 --- a/language/_____LANGUAGE_de/_____LANGUAGE_de.aod +++ b/language/_____LANGUAGE_de/_____LANGUAGE_de.aod @@ -7423,6 +7423,14 @@ <key>Dataset</key> <value>Datensatz</value> </entry> + <entry> + <key>Error</key> + <value>Fehler</value> + </entry> + <entry> + <key>File from this template could not be found anymore. Please go to the template and upload a new file.</key> + <value>Die Datei dieser Vorlage konnte nicht mehr gefunden werde. Bitte laden Sie bei der Dokumentvorlage eine neue Datei hoch.</value> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod index 85f45888ae3f6745e88d333f394188df9864d12f..27e36d62c23295ca97e07484e58dad9098839a58 100644 --- a/language/_____LANGUAGE_en/_____LANGUAGE_en.aod +++ b/language/_____LANGUAGE_en/_____LANGUAGE_en.aod @@ -5959,6 +5959,12 @@ <entry> <key>SqlBuilder: invalid value-type for pFieldOrCond. It can be a fully qualified SqlBuilder (e.g. select, from, ... have to be set) or an jdito-prepared-statement array</key> </entry> + <entry> + <key>Error</key> + </entry> + <entry> + <key>File from this template could not be found anymore. Please go to the template and upload a new file.</key> + </entry> </keyValueMap> <font name="Dialog" style="0" size="11" /> </language> diff --git a/process/DocumentTemplate_lib/process.js b/process/DocumentTemplate_lib/process.js index 6a72035ce55ea9c2420443bc2b040d38484437da..c03ac5eba780c1eff05eeaf68827927271a0341e 100644 --- a/process/DocumentTemplate_lib/process.js +++ b/process/DocumentTemplate_lib/process.js @@ -253,7 +253,12 @@ DocumentTemplate.loadTemplate = function (pAssignmentRowId, pAssignmentTable, pR if (templateId) { - return DocumentTemplateUtils.getTemplate(templateId, pResolveSubtemplates) + 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")); + return null; + } } var templateDocument = db.getBinaryMetadata(pAssignmentTable, "DOCUMENT", pAssignmentRowId, false, alias, null); @@ -305,7 +310,11 @@ DocumentTemplate.getSelectedTemplate = function (pTemplateId, pDocumentUpload, p if (pDocumentUpload.isFilled()) template = DocumentTemplate.fromUpload(pDocumentUpload); else if (pTemplateId) + { template = DocumentTemplate.loadTemplate(pTemplateId); + if (!template) + return null; + } else template = new DocumentTemplate(null, pDefaultType || DocumentTemplate.types.TXT, null, true); @@ -826,9 +835,8 @@ DocumentTemplateUtils.updateTemplateData = function (pTemplateId, pFileUpload, p var assignmentName= "DOCUMENT"; var keyword = "TEMPLATE"; var binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword); - if (binMeta.length == 0) - SingleBinaryUtils.insertMainDocument(assignmentTable, assignmentName, pTemplateId, pFileUpload.bindata, pFileUpload.filename, null, SqlUtils.getBinariesAlias()); + SingleBinaryUtils.insert(assignmentTable, assignmentName, pTemplateId, pFileUpload.bindata, pFileUpload.filename, null, "TEMPLATE", SqlUtils.getBinariesAlias()); else db.updateBinary(binMeta[0][db.BINARY_ID], "", pFileUpload.bindata, pFileUpload.filename, "", keyword, SqlUtils.getBinariesAlias()); } @@ -884,7 +892,6 @@ DocumentTemplateUtils.getTemplate = function (pTemplateId, pResolveSubtemplates) var keyword = "TEMPLATE"; var binMeta = db.getBinaryMetadata(assignmentTable, assignmentName, pTemplateId, false, SqlUtils.getBinariesAlias(), keyword); - if (binMeta.length != 0) { return new DocumentTemplate( diff --git a/process/Email_lib/process.js b/process/Email_lib/process.js index 64162b4cdb3541e722f3a4cd5ed74dcb503ab791..ac0b91e7693512bbcacb028e9f78a05487998180 100644 --- a/process/Email_lib/process.js +++ b/process/Email_lib/process.js @@ -33,9 +33,14 @@ EmailWritingUtils.openMailTemplate = function (pToRecipients, pSenderContactId, var email; if (pTemplateId || pBindata) + { email = Email.fromTemplate(pTemplateId, pRecipientContactId, pBindata) + if (!email) + email = new Email(); + } else email = new Email(); + email.setSender(pSenderContactId); if (pToRecipients) @@ -110,7 +115,12 @@ Email.fromTemplate = function (pTemplateId, pContactId, pBindata) if (pBindata && pBindata.isFilled() && BulkMailUtils.isValidMimeType(pBindata.mimeType)) template = new DocumentTemplate(pBindata.bindata, DocumentTemplate.types.fromMimeType(pBindata.mimeType), pBindata.filename, true); else + { template = DocumentTemplate.loadTemplate(pTemplateId); + if (!template) + return null; + } + return Email.getReplacedBulkEmails(template, [pContactId])[pContactId]; }