Error in Cases on Dev

Did some more digging into this. My custom/Cases/metadata/detailviewdefs.php has one entry that causes this. It is:

 9 =>
    array(
    0 =>
    array(
        'name' => 'case_update_form',
        'studio' => 'visible',
        'label' => 'LBL_CASE_UPDATE_FORM',
    ),
 ),

If I understand right this method is defined in /modules/Cases/vardefs which has this in it:

'case_update_form' => array(
    'required' => false,
    'name' => 'case_update_form',
    'vname' => 'LBL_CASE_UPDATE_FORM',
    'type' => 'function',
    'source' => 'non-db',
    'massupdate' => 0,
    'studio' => 'visible',
    'importable' => 'false',
    'duplicate_merge' => 'disabled',
    'duplicate_merge_dom_value' => 0,
    'audited' => false,
    'reportable' => false,
    'function' => array(
        'name' => 'display_update_form',
        'returns' => 'html',
        'include' => 'modules/AOP_Case_Updates/Case_Updates.php',
    ),
),

So looking at modules/AOP_Case_Updates/Case_Updates.php’ this display_update_form is:

/**
 * @return mixed|string|void
 */
function display_update_form()
{
    global $mod_strings, $app_strings;
    $sugar_smarty = new Sugar_Smarty();
    $sugar_smarty->assign('MOD', $mod_strings);
    $sugar_smarty->assign('APP', $app_strings);

    return $sugar_smarty->fetch('modules/AOP_Case_Updates/tpl/caseUpdateForm.tpl');
}

Which fetches modules/AOP_Case_Updates/tpl/caseUpdateForm.tpl which looks like this:

{*
/**
 *
 * SugarCRM Community Edition is a customer relationship management program developed by
 * ### REMOVED THE REST OF THE COMMENT ###".
 */
*}
<button id="addFileButton" class="button primary" type="button">{$MOD.LBL_ADD_CASE_FILE}</button>
{literal}
<script>
    $(document).ready(function(){
        var docCount = 0;
        $(document).on('change','.caseDocumentTypeSelect',function(){
            var wrapper = $(this).closest('.caseDocumentWrapper');
            if($(this).val() == 'internal'){
                wrapper.find('#case_update_file\\[\\]').hide();
                wrapper.find('.internalCaseDocumentWrapper').show();
            }else{
                wrapper.find('#case_update_file\\[\\]').show();
                wrapper.find('.internalCaseDocumentWrapper').hide();
            }

        });

        $('#addFileButton').click(function(e){
            var template = $('#updateFileRowTemplate').html();
            template = template.replace(/case_document_name/g, 'case_update_name_'+docCount);
            template = template.replace(/case_document_id/g, 'case_update_id_'+docCount);
            $(e.target).before(template);
            if(typeof sqs_objects == 'undefined'){
                sqs_objects = new Array;
            }
            sqs_objects['EditView_case_document_name_'+docCount]={
                "form":"EditView",
                "method":"query",
                'modules': 'Documents',
                "field_list":["name","id"],
                "populate_list":["case_document_name_"+docCount,"case_document_id_"+docCount],
                "required_list":["case_document_id_"+docCount],
                "conditions":[{"name":"name","op":"like_custom","end":"%","value":""}],
                "limit":"30",
                "no_match_text":"No Match"};
            SUGAR.util.doWhen(
                    "typeof(sqs_objects) != 'undefined' && typeof(sqs_objects['EditView_case_document_name_"+docCount+"']) != 'undefined'",
                    enableQS
            );

            $('.caseDocumentTypeSelect').change();
            docCount++;
        });
        $(document).on('click','.removeFileButton',function(e){
            $(e.target).closest('span').remove();
        });
    });
</script>
{/literal}
<script id="updateFileRowTemplate"  type="text/template">
    <span class="caseDocumentWrapper">
        <select class="caseDocumentTypeSelect">
            <option value="internal">{$MOD.LBL_SELECT_INTERNAL_CASE_DOCUMENT}</option>
            <option value="external">{$MOD.LBL_SELECT_EXTERNAL_CASE_DOCUMENT}</option>
        </select>
        <input type="file" id="case_update_file[]" name="case_update_file[]">
        <span class="internalCaseDocumentWrapper">
            <input type="text" name="case_document_name" class="sqsEnabled" tabindex="0" id="case_document_name" size="" value="" title='' autocomplete="off">
            <input type="hidden" name="case_document_id" id="case_document_id" value="">

            <span class="id-ff multiple">
                <button type="button" name="btn_case_document_name" id="btn_case_document_name" tabindex="0" title="{$MOD.LBL_SELECT_CASE_DOCUMENT}" class="button firstChild" value="{$MOD.LBL_SELECT_CASE_DOCUMENT}"
                        {literal}
                        onclick='open_popup(
                                "Documents",
                                600,
                                400,
                                "",
                                true,
                                false,
                                {"call_back_function":"set_return","form_name":"EditView","field_to_name_array":{"id":"case_document_id","name":"case_document_name"}},
                                "single",
                                true
                                );' >
                        {/literal}
                <span class="suitepicon suitepicon-action-select"></span></button>
                <button type="button" name="btn_clr_case_document_name"
                        id="btn_clr_case_document_name" tabindex="0" title="{$MOD.LBL_CLEAR_CASE_DOCUMENT}"  class="button lastChild"
                        onclick="SUGAR.clearRelateField(this.form, 'case_document_name', 'case_document_id');"  value="{$MOD.LBL_CLEAR_CASE_DOCUMENT}" ><span class="suitepicon suitepicon-action-clear"></span></button>
            </span>
        </span>

<button class="removeFileButton" type="button">{$MOD.LBL_REMOVE_CASE_FILE}</button><br>
    </span>

</script>

The first thing I see is the line above the last /literal. The > should be below the /literal. But moving it there and Repair and Rebuild does not seem to fix the problem. I think he > is in the wrong place. It should be after the {/literal}.

Digging Deeper. I grabbed the source of sugar_grp1.js which is in cache/include/javascript/. I edited this file and found the text “error adding script”. I added some console.log() commands to trace what was going on.

What I have found is that the file modules/AOP_Case_Updates/tpl/caseUpdateForm.tpl is parsed using the regular expression:

var srcRegex=/.*src=['"]([a-zA-Z0-9_\-\&\/\.\?=:-]*)['"].*/gim; var result=objRegex.exec(text);

The results used are result[1] and result[2].

Next result[1] is checked for "src=", (result[1].indexOf("src=") > -1). If found then the script loaded into the browser. If not found then result[2] is checked for a comment tag <!-- --> using regular expression.

var srcRegex=/<!--([\s\S]*?)-->/; var srcResult=srcRegex.exec(result[2]);

If found then SUGAR.util.globalEval() is done on srcResult[1]. If not found then SUGAR.util.globalEval() is done on result[2].

In this case as you can see above there are no comment tags in

<script id="updateFileRowTemplate" type="text/template">

so the code then attempts to eval(result[2]) which is NOT JavaScript resulting in an error I pasted in the previous message.

I think this is a bug. If I add comment tags this page loads just fine. I don’t know though if this will affect any pages. I presume it is only for Case Updates. Does anyone else know?

I did unzip several versions of SuiteCRM version 7.11.15, 7.11.22 and 7.12.5 (this is the version I am running) and diffed the tpl file on all of them and they do not differ.

Looking for some direction on how to fix this.

Tony