Error adding script in Cases #4839

Open
opened 2026-02-20 16:24:50 -05:00 by deekerman · 4 comments
Owner

Originally created by @tkoehn1962 on GitHub (Aug 19, 2022).

Issue

When creating a new case using the Create Case in the Cases sidebar the following error messages shows up in the web browser console.

The code looks for

Originally created by @tkoehn1962 on GitHub (Aug 19, 2022). #### Issue When creating a new case using the Create Case in the Cases sidebar the following error messages shows up in the web browser console. The code looks for <script> tags and performs an eval on the scripts that it finds. If the script has a src attribute it loads the script from the src address otherwise it does an eval on the code in the script tag. Scripts that have a type of text/template are still handled as if the code with in the tags are JavaScript but actually contain HTML code thus causing the error. #### Expected Behavior There should be no errors in the debug console. #### Actual Behavior Error occurs and is displayed in the web browsers JavaScript console. Some custom JavaScript routines did fail in my case. ``` error adding script sugar_grp1.js?v=d15fehRftK0vOxp4DrGprQ:425 SyntaxError: Unexpected token '<' at eval (<anonymous>) at sugar_grp1.js?v=d15fehRftK0vOxp4DrGprQ:418:156 at Object.globalEval (sugar_grp1.js?v=d15fehRftK0vOxp4DrGprQ:418:176) at Object.evalScript (sugar_grp1.js?v=d15fehRftK0vOxp4DrGprQ:424:17) at Object.callback [as success] (sugar_grp1.js?v=d15fehRftK0vOxp4DrGprQ:619:98) at Object.handleTransactionResponse (sugar_grp1_yui.js?v=d15fehRftK0vOxp4DrGprQ:31:4422) at sugar_grp1_yui.js?v=d15fehRftK0vOxp4DrGprQ:31:3935 sugar_grp1.js?v=d15fehRftK0vOxp4DrGprQ:425 [ "<script id=\"updateFileRowTemplate\" type=\"text/template\">\n <span class=\"caseDocumentWrapper\">\n <select class=\"caseDocumentTypeSelect\">\n <option value=\"internal\">Internal CRM document</option>\n <option value=\"external\">External file</option>\n </select>\n <input type=\"file\" id=\"case_update_file[]\" name=\"case_update_file[]\">\n <span class=\"internalCaseDocumentWrapper\">\n <input type=\"text\" name=\"case_document_name\" class=\"sqsEnabled\" tabindex=\"0\" id=\"case_document_name\" size=\"\" value=\"\" title='' autocomplete=\"off\">\n <input type=\"hidden\" name=\"case_document_id\" id=\"case_document_id\" value=\"\">\n\n <span class=\"id-ff multiple\">\n <button type=\"button\" name=\"btn_case_document_name\" id=\"btn_case_document_name\" tabindex=\"0\" title=\"Select document\" class=\"button firstChild\" value=\"Select document\"\n \n onclick='open_popup(\n \"Documents\",\n 600,\n 400,\n \"\",\n true,\n false,\n {\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":\"case_document_id\",\"name\":\"case_document_name\"}},\n \"single\",\n true\n );' >\n \n <span class=\"suitepicon suitepicon-action-select\"></span></button>\n <button type=\"button\" name=\"btn_clr_case_document_name\"\n id=\"btn_clr_case_document_name\" tabindex=\"0\" title=\"Clear document\" class=\"button lastChild\"\n onclick=\"SUGAR.clearRelateField(this.form, 'case_document_name', 'case_document_id');\" value=\"Clear document\" ><span class=\"suitepicon suitepicon-action-clear\"></span></button>\n </span>\n </span>\n\n<button class=\"removeFileButton\" type=\"button\">Remove file</button><br>\n </span>\n\n</script>", " id=\"updateFileRowTemplate\" type=\"text/template\"", "\n <span class=\"caseDocumentWrapper\">\n <select class=\"caseDocumentTypeSelect\">\n <option value=\"internal\">Internal CRM document</option>\n <option value=\"external\">External file</option>\n </select>\n <input type=\"file\" id=\"case_update_file[]\" name=\"case_update_file[]\">\n <span class=\"internalCaseDocumentWrapper\">\n <input type=\"text\" name=\"case_document_name\" class=\"sqsEnabled\" tabindex=\"0\" id=\"case_document_name\" size=\"\" value=\"\" title='' autocomplete=\"off\">\n <input type=\"hidden\" name=\"case_document_id\" id=\"case_document_id\" value=\"\">\n\n <span class=\"id-ff multiple\">\n <button type=\"button\" name=\"btn_case_document_name\" id=\"btn_case_document_name\" tabindex=\"0\" title=\"Select document\" class=\"button firstChild\" value=\"Select document\"\n \n onclick='open_popup(\n \"Documents\",\n 600,\n 400,\n \"\",\n true,\n false,\n {\"call_back_function\":\"set_return\",\"form_name\":\"EditView\",\"field_to_name_array\":{\"id\":\"case_document_id\",\"name\":\"case_document_name\"}},\n \"single\",\n true\n );' >\n \n <span class=\"suitepicon suitepicon-action-select\"></span></button>\n <button type=\"button\" name=\"btn_clr_case_document_name\"\n id=\"btn_clr_case_document_name\" tabindex=\"0\" title=\"Clear document\" class=\"button lastChild\"\n onclick=\"SUGAR.clearRelateField(this.form, 'case_document_name', 'case_document_id');\" value=\"Clear document\" ><span class=\"suitepicon suitepicon-action-clear\"></span></button>\n </span>\n </span>\n\n<button class=\"removeFileButton\" type=\"button\">Remove file</button><br>\n </span>\n\n", "\n" ] ``` #### Possible Fix To fix I wrapped lines 3009-3016 in the file jssource/src_files/include/javascript/sugar_3.js with an if statement to check to see if the script is a text/template. If so, then don't eval. From: ``` var srcRegex = /<!--([\s\S]*?)-->/; var srcResult = srcRegex.exec(result[2]); if (srcResult && srcResult.index > -1) { SUGAR.util.globalEval(srcResult[1]); } else { SUGAR.util.globalEval(result[2]); } ``` To: ``` if (result[1].indexOf("text/template") == -1) { var srcRegex = /<!--([\s\S]*?)-->/; var srcResult = srcRegex.exec(result[2]); if (srcResult && srcResult.index > -1) { SUGAR.util.globalEval(srcResult[1]); } else { SUGAR.util.globalEval(result[2]); } } ``` Followed by running the admin command <b>Rebuild JS Grouping Files</b> and <b>Quick Repair and Rebuild</b>. #### Steps to Reproduce 1. Select Cases 2. Open Web browsers debug console 3. Click on Create Case in the Sidebar 4. Error display in the web browsers debug console #### Context This is a low priority bug but none the less it causes an error in the web console. If you have custom Javascript in the custom/modules/Cases/js/editView.js as I do, this may prevent your code from executing events. #### Your Environment * SuiteCRM Version used: Tested on SuiteCRM versions 7.12.5, 7.12.6 (demo.suiteondemand.com), 7.12.7 * Browser name and version: Ubuntu 20.04 Chrome Version 104.0.5112.79 (Official Build) (64-bit), Ubutu 20.04 Firefox Version 103.0 (64-bit), Windows Chrome Version 104.0.5112.82 (Official Build) (64-bit), Edge Version 104.0.1293.54 (Official build) (64-bit) * Environment name and version: MySQL, PHP 7.3 * Operating System and version: Ubuntu 20.04, Windows 10, Windows 11
Author
Owner

@SuiteBot commented on GitHub (Aug 19, 2022):

This issue has been mentioned on SuiteCRM. There might be relevant details there:

https://community.suitecrm.com/t/error-in-cases-on-dev/84750/15

@SuiteBot commented on GitHub (Aug 19, 2022): This issue has been mentioned on **SuiteCRM**. There might be relevant details there: https://community.suitecrm.com/t/error-in-cases-on-dev/84750/15
Author
Owner

@pgorod commented on GitHub (Aug 20, 2022):

This generic fix is interesting! I hope it's not too bad for performance, those regexps?

Still, there's probably an underlying specific bug here, one of the scripts being echoed isn't properly formatted, it would be good to fix that also.

@pgorod commented on GitHub (Aug 20, 2022): This generic fix is interesting! I hope it's not too bad for performance, those regexps? Still, there's probably an underlying specific bug here, one of the scripts being echoed isn't properly formatted, it would be good to fix that also.
Author
Owner

@tkoehn1962 commented on GitHub (Jun 16, 2023):

Updated to SuiteCRM 7.13.3 and this problem still exists. Applied my patch to prevent the error.

@tkoehn1962 commented on GitHub (Jun 16, 2023): Updated to SuiteCRM 7.13.3 and this problem still exists. Applied my patch to prevent the error.
Author
Owner

@pgorod commented on GitHub (Jun 17, 2023):

@tkoehn1962 are you using any language pack? Does the error also manifest itself with just the basic English language?

@pgorod commented on GitHub (Jun 17, 2023): @tkoehn1962 are you using any language pack? Does the error also manifest itself with just the basic English language?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4839
No description provided.