Custom JavaScript code is not executed for 'create' only for 'edit' operations

Hi,
I defined some JavaScript code to be executed when working with the ‘editview’ of a module. This works fine without errors when I edit an already existing record. When creating a new record, I get an error in the JavaScript console, which says:

sugar_grp1_yui.js?v=7aThOBuXRfTTKf0x19Do4g:16 GET http://127.0.0.1/abc/src=%22custom/Extension/javascript/custom_js.js?v=7aThOBuXRfTTKf0x19Do4g%22 403 (Forbidden)

The problem seems to be the ‘src=’ substring in the GET command. This is obviously not a valid file path. It seems when creating a record the string for accessing the JavaScript is erroneously build. At least I am not surprised that is says 403 Forbidden as error - this file does not exist. It should be …/abc/custom/ not …/abc/src=%22custom
This only happens for creating new records not when editing existing ones, which confuses me a bit. I would expect that both are the same operation just that one is populated with field values from the DB while the other one is blank…

I am rather new to SuiteCRM and I would appreciate any ideas how to trace this error.

Best,

Hi, welcome.

I don’t think it’s possibly to help you unless you provide the exact paths and contents of your customizations… if you don’t know what you did, we can’t find out how you broke things… :wink:

And don’t forget to tell us your SuiteCRM version, please

I will try my best to provide you all needed details :). My JavaScript code looks like this - it just adds a line of text to the end of the panel. The file is called custom_js.js and is located in '<my_module>/Ext/javascript/custom_js.js

The content:


$(function(){
	document.getElementById('detailpanel_-1').innerHTML+='<span> * marks mandatory information</span></p><br>';
});

I added the JavaScript extension by editing the editviewdefs.php and adding the ‘includes’ entry to the array pointing to above file


$viewdefs [$module_name] = 
array (
  'EditView' => 
  array (
    'templateMeta' => 
    array (
      'maxColumns' => '2',
      'widths' => 
      array (
        0 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
        1 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
      ),
      'includes' => 
      array (
        0 => 
        array (
          'file' => 'custom\\modules\\<my_module>\\Ext\\javascript\\custom_js.js',
        ),
      ),
      'useTabs' => false,
      'tabDefs' => 
      array (
        'DEFAULT' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
      ),

I am working on Windows and I use SuiteCRM 7.11.4 (Sugar 6.5.25, Build 344).
Do you need more/other information?

Thanks.

Can you try all Javascript repairs from Admin/Repairs? Including the one about “groupings”

Is your Javascript function getting loaded (included) with the page? I assume not, given the error message, but I just want to check.

EDIT: I think you shouldn’t be putting your custom file in that place, you shouldn’t mix this with the Extension framework. Just put somewhere like this:

‘file’ => ‘custom/modules/Accounts/myCustomFile.js’,

1 Like

Hi,

I used all repair choices which related to JavaScript but this did not help. The error 403-forbidden remains and no, the script code is not added to my web page.

Is there a way to find the location in the backend where this string for accessing the javascript file is build?

Thanks for the help so far!

Did you move the file to where I told you in my “edit” above?

Ah, sorry. No, I didn’t. Now it works. Thank you!

I positioned this file outside the module folder because I need it in various modules. Is there a folder where scripts for multiple modules should be stored?

Can you explain to me why the edit-operation did succeed while the create did fail to find/use/load the file? I still don’t fully understand the problem ?

Thanks a lot :slight_smile:

I think you can put it wherever you want, since it uses a direct reference the system should pick it up (from “custom”, or “custom/modules”, if you want).

I don’t know how to explain the previous behavior - the Extension framework aggregates pieces of customization into a new file that gets used by the system. So what happens there also depends on what other files you have in your system. But I can’t see how it could make a difference between one view and the other :huh:

I’ve just had the same issue in SuiteCRM 7.11 as well. It seems like when specifying path using \\ it does prepend src= to the request path for some reason (Only happens in creation page. Edit page works both ways). However specifying path with / seems to work fine.

Wrong:

'includes' =>
            array (
                0 =>
                    array (
                        'file' => 'custom\\modules\\abcde_ADMIN_Bots\\randomPerformanceSelector.js',
                    ),
            ),

Correct:

'includes' =>
            array (
                0 =>
                    array (
                        'file' => 'custom/modules/abcde_ADMIN_Bots/randomPerformanceSelector.js',
                    ),
            ),