diff --git a/entity/DocumentTemplate_entity/entityfields/classification/mandatoryProcess.js b/entity/DocumentTemplate_entity/entityfields/classification/mandatoryProcess.js index b6725a540edf2aa0e44bce526b568c8ed7df916f..1e11aa4b73da895b54394e7f285fb7b764ba4d45 100644 --- a/entity/DocumentTemplate_entity/entityfields/classification/mandatoryProcess.js +++ b/entity/DocumentTemplate_entity/entityfields/classification/mandatoryProcess.js @@ -2,4 +2,5 @@ import("KeywordRegistry_basic"); import("system.vars"); import("system.result"); -result.object(vars.get("$field.KIND") != $KeywordRegistry.documentTemplateType$attachment()) \ No newline at end of file +result.object(vars.get("$field.KIND") != $KeywordRegistry.documentTemplateType$attachment() + && vars.get("$field.KIND") != $KeywordRegistry.documentTemplateType$signature()); \ No newline at end of file diff --git a/entity/ServiceEmail_entity/entityfields/email_body_content/displayValueProcess.js b/entity/ServiceEmail_entity/entityfields/email_body_content/displayValueProcess.js index 96b4a1caacff31c0c432d9b97b9702e0d5ac9d28..51a8372596fac379c9f4edf992372b100bb494e1 100644 --- a/entity/ServiceEmail_entity/entityfields/email_body_content/displayValueProcess.js +++ b/entity/ServiceEmail_entity/entityfields/email_body_content/displayValueProcess.js @@ -3,9 +3,16 @@ import("Util_lib"); import("system.neon"); import("system.vars"); -if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET && vars.get("$field.textbox")) +if (vars.get("$sys.viewmode") == neon.FRAME_VIEWMODE_DATASET) { var preview = vars.get("$field.EMAIL_BODY_CONTENT") - preview = StringUtils.replaceAll(preview.toString(), "{@Service@}", vars.get("$field.textbox")); - result.string(preview); + if (vars.get("$field.textbox")) + { + preview = StringUtils.replaceAll(preview.toString(), "{@Service@}", vars.get("$field.textbox")); + } + else + { + preview = StringUtils.replaceAll(preview.toString(), "{@Service@}", ""); + } + result.string(preview); } \ No newline at end of file diff --git a/entity/ServiceEmail_entity/recordcontainers/jdito/onInsert.js b/entity/ServiceEmail_entity/recordcontainers/jdito/onInsert.js index b8b01338db50ae9918fd1b97ef65274a7095116a..7bf43f8059cadfb954c8c13675165b4db855cb25 100644 --- a/entity/ServiceEmail_entity/recordcontainers/jdito/onInsert.js +++ b/entity/ServiceEmail_entity/recordcontainers/jdito/onInsert.js @@ -22,7 +22,7 @@ var TicketfieldValues = {}; var fromEmail = vars.get("$field.from"); var subject = vars.get("$field.subject"); -var contentHtml = vars.get("$field.EMAIL_BODY_CONTENT"); +var contentHtml = vars.get("$field.EMAIL_BODY_CONTENT.displayValue"); var contactId = vars.get("$param.ContactId_param"); diff --git a/entity/SupportTicket_entity/entityfields/task_requestor_contact_id/onValueChange.js b/entity/SupportTicket_entity/entityfields/task_requestor_contact_id/onValueChange.js index 713a33ff04c0a5c52e29e61875657926aea4a3d5..563673fcbbc2a5383b123991053823e2e7b48adb 100644 --- a/entity/SupportTicket_entity/entityfields/task_requestor_contact_id/onValueChange.js +++ b/entity/SupportTicket_entity/entityfields/task_requestor_contact_id/onValueChange.js @@ -20,13 +20,13 @@ if( str_requestorContactId) .and( "communication.MEDIUM_ID in ('COMMPHONE', 'COMMMOBIL')") .orderBy("communication.ISSTANDARD desc") .cell(); - if(str_email) + if(str_email && vars.exists("$field.CommEMail")) { neon.setFieldValue("$field.CommEmail", str_email ); } - if(str_phone) + if(str_phone && vars.exists("$field.CommPhone")) { neon.setFieldValue("$field.CommPhone", str_phone diff --git a/process/mailbridge_service/process.js b/process/mailbridge_service/process.js index 3ef8fb533a55ffc0f00eef9d3796bb3ed63dc669..d05860bd63f461478032db7608b67490aabc4839 100644 --- a/process/mailbridge_service/process.js +++ b/process/mailbridge_service/process.js @@ -58,7 +58,7 @@ TicketMailbridgeUtils.insertLog = function(pTicketId, pDescription) * @param {String} pSpecificRecipients <p> * Recipients (Mail address) of the incoming mail<br> * @return {Array} <p> -* Array of Ids of matching Inboxes +* Array of inboxes */ TicketMailbridgeUtils.getInbox = function (pSpecificRecipients) { @@ -67,6 +67,24 @@ TicketMailbridgeUtils.getInbox = function (pSpecificRecipients) .from("INBOX") .leftJoin("MAILSIGNATURE", "INBOX.INBOXID = MAILSIGNATURE.INBOX_ID") .whereIfSet("INBOX.EMAIL_ADDRESS", pSpecificRecipients, SqlBuilder.IN()) + .or("MAILSIGNATURE.MAIL_ADDRESS", pSpecificRecipients, SqlBuilder.IN()) + .arrayRow(); + return inboxID; +} + +/* +* Find default inbox via default mailsignature +* +* @return {Array} <p> +* Array with ID, Reopen delay and mail-address of the inbox with the default mailsignature +*/ +TicketMailbridgeUtils.getDefaultInbox = function () +{ + var inboxID = new SqlBuilder() + .select(["INBOX.INBOXID","INBOX.REOPEN_DELAY", "INBOX.EMAIL_ADDRESS"]) + .from("INBOX") + .leftJoin("MAILSIGNATURE", "INBOX.INBOXID = MAILSIGNATURE.INBOX_ID") + .where("MAILSIGNATURE.DEFAULTSIGNATURE", 1) .arrayRow(); return inboxID; } @@ -87,37 +105,61 @@ TicketMailbridgeUtils.getInbox = function (pSpecificRecipients) */ TicketMailbridgeUtils.getInboxInformationAllRecipients = function(pRecipients, pSender, possibleBCC, possibleBCCUnfiltered) { - var inboxObj = {}; + var inboxObj = {}; + var inboxFound = false; var inboxInformation; - inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(pRecipients); - - // found an Inbox? - if(inboxObj.inboxID.length > 0) - { - inboxInformation = TicketMailbridgeUtils.getInboxInformation(pRecipients,inboxObj["inboxID"][0]); - inboxObj["reoplenDelay"] = inboxInformation[0]; - inboxObj["mailSignatureID"] = inboxInformation[1]; - } - else // try to find some from possible BCC without INBOX-Mails + + // try to find an Inbox via Recipients + if (pRecipients != "") { - inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCC); + inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(pRecipients); if(inboxObj.inboxID.length > 0) - { - TicketMailbridgeUtils.getInboxInformation(possibleBCC,inboxObj["inboxID"][0]) - inboxObj["reoplenDelay"] = inboxInformation[0]; - inboxObj["mailSignatureID"] = inboxInformation[1]; - } - else { - inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCCUnfiltered); - if(inboxObj.inboxID.length > 0) - { - TicketMailbridgeUtils.getInboxInformation(possibleBCCUnfiltered,inboxObj["inboxID"][0]) - inboxObj["reoplenDelay"] = inboxInformation[0]; - inboxObj["mailSignatureID"] = inboxInformation[1]; - } + inboxInformation = TicketMailbridgeUtils.getInboxInformation(pRecipients,inboxObj["inboxID"][0]); + inboxObj["reopenDelay"] = inboxInformation[0]; + inboxObj["mailSignatureID"] = inboxInformation[1]; + inboxFound = true; } } + // try to find inbox from possible BCC without INBOX-Mails + if (possibleBCC != "" && inboxFound == false ) + { + inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCC); + // found an Inbox? + if(inboxObj.inboxID.length > 0) + { + inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCC,inboxObj["inboxID"][0]); + inboxObj["reopenDelay"] = inboxInformation[0]; + inboxObj["mailSignatureID"] = inboxInformation[1]; + inboxFound = true; + } + } + // use BACKUP INBOX-Mails + if (possibleBCCUnfiltered != "" && inboxFound == false ) + { + inboxObj["inboxID"] = TicketMailbridgeUtils.getInbox(possibleBCCUnfiltered); + // found an Inbox? + if(inboxObj.inboxID.length > 0) + { + inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCCUnfiltered,inboxObj["inboxID"][0]); + inboxObj["reopenDelay"] = inboxInformation[0]; + inboxObj["mailSignatureID"] = inboxInformation[1]; + inboxFound = true; + } + } + // else use the Inbox with the default mailsignature + if (inboxFound == false) + { + inboxObj["inboxID"] = TicketMailbridgeUtils.getDefaultInbox(); + // found an Inbox? + if(inboxObj.inboxID.length > 0) + { + inboxInformation = TicketMailbridgeUtils.getInboxInformation(possibleBCCUnfiltered,inboxObj["inboxID"][0]); + inboxObj["reopenDelay"] = inboxInformation[0]; + inboxObj["mailSignatureID"] = inboxInformation[1]; + inboxFound = true; + } + } inboxObj["filterArray"] = newSelect("RTRIM(COMPONENT), searchterm, TICKETTEMPLATE_ID, " + "( case when ifnull(INBOXFILTERGROUP.PRIORITY,999) = 0 then 999 " @@ -174,12 +216,24 @@ TicketMailbridgeUtils.getInboxInformationAllRecipients = function(pRecipients, p */ TicketMailbridgeUtils.getInboxInformation = function(pSpecificRecipients, pInboxId) { - var reopenDelay = newSelect("INBOX.INBOXID, INBOX.REOPEN_DELAY ") + if (pSpecificRecipients != "") + { + var reopenDelay = newSelect("INBOX.REOPEN_DELAY ") .from("INBOX") .leftJoin("MAILSIGNATURE", "MAILSIGNATURE.INBOX_ID = INBOX.INBOXID") .whereIfSet("INBOX.EMAIL_ADDRESS", pSpecificRecipients, SqlBuilder.IN()) .or("MAILSIGNATURE.MAIL_ADDRESS", pSpecificRecipients, SqlBuilder.IN()) - .arrayRow()[1]; + .cell(); + } + else + { + var reopenDelay = newSelect("INBOX.REOPEN_DELAY ") + .from("INBOX") + .leftJoin("MAILSIGNATURE", "MAILSIGNATURE.INBOX_ID = INBOX.INBOXID") + .whereIfSet("MAILSIGNATURE.DEFAULTSIGNATURE", 1) + .cell(); + } + var mailSignatureSelect = [ @@ -663,29 +717,35 @@ TicketMailbridgeUtils.createTicket = function(pMailObject, pFilterResult, pInbox // sending Automatic Answeremail if(answerMail != "" && answerMail != undefined && answerMailActive !="" && answerMailActive == true) { - logging.log(answerMail); - var eml = new Email(); - eml.sender = mailRec || inboxUser; - eml.subject = ticketSub +" ["+ ticketCode +"]"; + var eml = new Email(); + // use answer mail address, if answer mail address is set for the selected inbox + var commAddr = pInboxObj.mailSignatureID[6]; // answer_mail_address + if (commAddr) + { + eml.sender = commAddr || inboxUser; + } + else + { + eml.sender = mailRec || inboxUser; + } - eml.body = DocumentTemplateUtils.getTemplate(answerMail, false) + "\n"+ DocumentTemplateUtils.getTemplate(signature, false) ; - eml.toRecipients = [persFrom]; - logging.log(JSON.stringify(DocumentTemplateUtils.getTemplate(answerMail))); - // overwrite eml.body with individual answer, if individual answer template is set for the selected ticket template + // use individual answer, if individual answer template is set for the selected ticket template + var bodyDocuTempl = DocumentTemplateUtils.getTemplate(signature, false); var indiAns = TicketTemplateUtils.checkIndividualAnswer(ticketTemplateId[0]); if(indiAns !="" && indiAns != undefined) { - eml.body = DocumentTemplateUtils.getTemplate(indiAns, false) + "\n"+ DocumentTemplateUtils.getTemplate(signature, false); + eml.body = StringUtils.replaceAll(bodyDocuTempl.toString(), "{@Service@}", DocumentTemplateUtils.getTemplate(indiAns, false)); } - // overwrite eml.sender with answer mail address, if answer mail address is set for the selected inbox - - var commAddr = pInboxObj.mailSignatureID[6]; // answer_mail_address - if (commAddr) - eml.sender = commAddr || inboxUser; + else + { + eml.body = StringUtils.replaceAll(bodyDocuTempl.toString(), "{@Service@}", DocumentTemplateUtils.getTemplate(answerMail, false)); + } + + eml.subject = ticketSub +" ["+ ticketCode +"]"; + eml.toRecipients = [persFrom]; var senderUser = tools.getUserByAttribute(tools.EMAIL, [inboxUser], tools.PROFILE_FULL); - // If it works then... if( eml.send(senderUser[tools.TITLE])) {