Summary:

On attempting to send an email from a template in Sage CRM, an error may be displayed. the issue does not affect the sending of emails that are not templates, or when a default template is selected.

When a recipient has been entered, and the Send E-mail button is selected, the following error message is displayed:

        You must have at least one valid address in the To, CC, or BCC boxes

The email will not send, and all of the fields on the screen will be set to their default original values.


Symptoms:

Emails do not send via CRM email client when using an email template.


Status:

This is a known error and has been resolved in 7.3c hotfix 1.


Workaround:

The issue can be worked around by adding the following as a Custom Content script to CommunicationDetailBox on the Communication entity.

<script>
/*
    Workaround for Sage CRM L3 case 0-165398.
   
    Creates hidden textareas for comm_to, comm_cc, comm_bcc
    if only emte_to, emte_cc, emte_bcc are present

 

    Add as a Custom Content script on EmailFilingBox
*/

 

var applyingWorkaround_0_165398 = false;

 

function getFirstParmValue (parmName) {

 

    var queryDict = {};
    location.search.substr(1).split("&").forEach(function(item) {queryDict[item.split("=")[0]] = item.split("=")[1]});
    return queryDict[parmName];
}

 

function isBlankNullOrUndefined (val) {

 

    val = val + "";
               
    if ((val == "") || (val == "undefined") || (val == "null")) return true;
     else return false;
}

 

function setToCcBccSubjectBody_WORKAROUND () {

 

    if($("#emte_to").length && $("#comm_to").val().length<1) $("#comm_to").val($("#emte_to").val());
    if($("#emte_cc").length && $("#comm_cc").val().length<1) $("#comm_cc").val($("#emte_cc").val());
    if($("#emte_bcc").length && $("#comm_bcc").val().length<1) $("#comm_bcc").val($("#emte_bcc").val());
    if($("#emte_comm_note").length && $("#comm_subject").val().length<1) $("#comm_subject").val($("#emte_comm_note").val());
    if($("#emte_comm_email").length && $("#comm_email").val().length<1) $("#comm_email").val($("#emte_comm_email").val());
}

 

function testAndAddEmailField_WORKAROUND(elemId) {

 

    if (!$("#"+elemId+"").length) {

 

        applyingWorkaround_0_165398 = true;   
        var $strCommTo = '<textarea name="'+elemId+'" id="'+elemId
            + '" type="hidden" maxlength="8000" style="display:none;"></textarea>';
        $('[name="EntryForm"]').append($strCommTo);
    }
}

 

crm.ready(function () {

 

    console.log("Workaround script for Sage CRM L3 case 0-165398-QA (email template issue) present on EmailFilingBox");

 

    // Fix "To" field when navigating from within a company context
    // Append any comm_to value from the current URL to the action on the template select

 

    var emailFromUrlParm = getFirstParmValue("comm_to");
   
    if (!isBlankNullOrUndefined(emailFromUrlParm)) {

 

        $('#template').attr("onchange", ($('#template').attr("onchange")+"").replace("';document.EntryForm", "&comm_to=" + emailFromUrlParm + "';document.EntryForm"));

 

        // Check if email address from URL has been applied
       
        if(!$('#emte_to').val()) $('#emte_to').append(getFirstParmValue("comm_to") + ";");
       
        console.log("EmailFilingBox: Applied workaround for 0-165479")
    }
   
    //Monitor for file uploads and fill localstorage: case 0-165508
        $('.SmallButtonItem').click(function() {
                   
            localStorage.setItem('emailBody',CKEDITOR.instances['edit'].getData());
            localStorage.setItem('emailTo', $('#emte_to').val());
            localStorage.setItem('emailCC', $('#emte_cc').val());
            localStorage.setItem('emailBCC', $('#emte_bcc').val());
            localStorage.setItem('emailSubject',$('#emte_comm_note').val());
        });
   
        //fill fields from localStorage after they disappeared due to attaching a file
        if(localStorage.getItem('emailBody') != null) CKEDITOR.instances['edit'].setData(localStorage.getItem('emailBody'));
        if(localStorage.getItem('emailTo') != null)$('#comm_to').val(localStorage.getItem('emailTo'));
        if(localStorage.getItem('emailCC') != null)$('#comm_cc').val(localStorage.getItem('emailCC'));
        if(localStorage.getItem('emailBCC') != null)$('#comm_bcc').val(localStorage.getItem('emailBCC'));
        if(localStorage.getItem('emailSubject') != null)$('#comm_subject').val(localStorage.getItem('emailSubject'));
       
        console.log("Applied workaround changes for Sage CRM L3 case 0-165508 - template attachments issue")
       
    // Check if a template is selected

 

    if ($('#_HIDDENtemplate').val()>0) {
   
        testAndAddEmailField_WORKAROUND("comm_to");
        testAndAddEmailField_WORKAROUND("comm_cc");
        testAndAddEmailField_WORKAROUND("comm_bcc");

 

        if (applyingWorkaround_0_165398) {
       
            // Fix Subject field (input maxlength = 255)
            // emte_comm_note -> comm_subject       
           
            if (!$("#comm_subject").length) {
           
                var $strCommSubject = '<input name="comm_subject" id="comm_subject" type="hidden" '
                    + 'maxlength="255" type="hidden"></input>';
                $('[name="EntryForm"]').append($strCommSubject);
            }
           
            // Fix body           
            // emte_comm_email -> comm_email       
               
            if (!$("#comm_email").length) {
           
                var $strCommBody = '<input name="comm_email" id="comm_email" type="hidden" type="hidden"></input>';
                $('[name="EntryForm"]').append($strCommBody);
            }       

 

            // Send button
   
            var strSubmitHref = "javascript:try{if(SageCRM.wsEmailClient.SubmitEmail('"
                + crm.getTrans("GenCaptions", "confirmfileonsend") + "', true, 'emte_comm_')==true) { "
                + "setToCcBccSubjectBody_WORKAROUND(); self.document.EntryForm.submit();} "
                + "else {void(0)}}catch(err){alert(err + '"
                + crm.getTrans("Errors", "wronguploadfilepath") + "')}";
       
            $('#Button_Send').attr('href', strSubmitHref);
   
            // Send Anyway button
           
            var strSubmitAnywayHref = "javascript:document.EntryForm.sendanyway.value='Y';"
                + "SageCRM.wsEmailClient.SubmitEmail('"
                + crm.getTrans("GenCaptions", "confirmfileonsend") + "', true, 'emte_comm_'); "
                + "try{if( $('input[name=_HIDDEN_comm_dotnetdll]').length > 0 ) { "
                + "var prevUrl = $('input[name=PrevCustomURL]').val(); "
                + "if(prevUrl != ''){ "
                + "document.forms.EntryForm.action = document.forms.EntryForm.action + "
                + "'&_HIDDEN_comm_dotnetdll=Y&PrevCustomURL='+escape(prevUrl)} };"
                + "SageCRM.webTriPage.checkSubmit(self.document.EntryForm);}catch(e){ "
                + "setToCcBccSubjectBody_WORKAROUND; self.document.EntryForm.submit();}";
       
            $('#Button_SendAnyway').attr('href', strSubmitAnywayHref);           
   
            console.log("Applied workaround for Sage CRM L3 case 0-165398-QA");
        }
    }
    else console.log("Script for 0-165398-QA has made no changes")
});
</script>