trouble adding JS libraries

Hi and thank you for read it,

I’m recently start to work qith SuiteCRM, and I’ve got some troubles when I add JS files to a module,

I did in 3 different ways without success

1st: trought a logic_hook but nothing happened
2nd: trought the view.edit.php and I got the same trouble
3rd:trought editviewdefs.php file, and the js works after a quick repair, but any movement in studio or after some time, the JS begins to fail, I can repair cleaning cache and cookies from my browser, but I cant do it every time it fails.

so the question now is if you know how to prevent that error?
or do you know another way to add a js file in an specific module?

Thanks for your support

https://developer.sugarcrm.com/2013/09/06/adding-javascript-files-to-edit-and-detail-views/

1 Like

Hi, thank for your reply,

that’s what I did to add the JS satisfactory but any movement in studio or after some time, the JS begins to fail and Suite did not recognize JS scripts, I checked the editviewdefs and it is overwrited.

here is an example of code.

Thanks for the support


<?php
$viewdefs ['Accounts'] = 
array (
  'EditView' => 
  array (
    'templateMeta' => 
    array (
      'form' => 
      array (
        'buttons' => 
        array (
          0 => 'SAVE',
          1 => 'CANCEL',
        ),
      ),
      'maxColumns' => '2',
      'widths' => 
      array (
        0 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
        1 => 
        array (
          'label' => '10',
          'field' => '30',
        ),
      ),
      'includes' => 
      array (
        0 => 
        array (
          'file' => 'custom_folder/libs_js/jquery.js',
        ),
        1 => 
        array (
          'file' => 'custom_folder/libs_js/jquery-ui.js',
        ),
        2 => 
        array (
          'file' => 'custom_folder/libs_js/HandlerCommonMethods.js',
        ),
        3 => 
        array (
          'file' => 'custom_folder/Modulos/Clientes/js/editview.js',
        ),
        4 => 
        array (
          'file' => 'modules/Accounts/Account.js',
        ),
      ),
      'useTabs' => false,
      'tabDefs' => 
      array (
        'LBL_ACCOUNT_INFORMATION' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
        'LBL_PANEL_ADVANCED' => 
        array (
          'newTab' => false,
          'panelDefault' => 'expanded',
        ),
      ),
    ),
    'panels' => 
    array (
      'lbl_account_information' => 
      array (
        0 => 
        array (
          0 => 
          array (
            'name' => 'name',
            'label' => 'LBL_NAME',
            'displayParams' => 
            array (
              'required' => true,
            ),
          ),
          1 => 
          array (
            'name' => 'phone_office',
            'label' => 'LBL_PHONE_OFFICE',
          ),
        ),
        1 => 
        array (
          0 => 
          array (
            'name' => 'email1',
            'studio' => 'false',
            'label' => 'LBL_EMAIL',
          ),
          1 => 
          array (
            'name' => 'website',
            'type' => 'link',
            'label' => 'LBL_WEBSITE',
          ),
        ),
        2 => 
        array (
          0 => 
          array (
            'name' => 'billing_address_street',
            'hideLabel' => true,
            'type' => 'address',
            'displayParams' => 
            array (
              'key' => 'billing',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),
          1 => 
          array (
            'name' => 'shipping_address_street',
            'hideLabel' => true,
            'type' => 'address',
            'displayParams' => 
            array (
              'key' => 'shipping',
              'copy' => 'billing',
              'rows' => 2,
              'cols' => 30,
              'maxlength' => 150,
            ),
          ),
        ),
        3 => 
        array (
          0 => 
          array (
            'name' => 'description',
            'label' => 'LBL_DESCRIPTION',
          ),
        ),
      ),
      'LBL_PANEL_ADVANCED' => 
      array (
        0 => 
        array (
          0 => 'account_type',
          1 => 
          array (
            'name' => 'other_account_type_c',
            'label' => 'LBL_OTHER_ACCOUNT_TYPE',
          ),
        ),
        1 => 
        array (
          0 => 'industry',
          1 => 
          array (
            'name' => 'other_industry_c',
            'label' => 'LBL_OTHER_INDUSTRY',
          ),
        ),
        2 => 
        array (
          0 => 'employees',
          1 => 'campaign_name',
        ),
        3 => 
        array (
          0 => 
          array (
            'name' => 'assigned_user_name',
            'label' => 'LBL_ASSIGNED_TO',
          ),
        ),
      ),
    ),
  ),
);
$viewdefs['Accounts']['EditView']['templateMeta'] = array (
'includes' => 
      array (
        0 => 
        array (
          'file' => 'custom_estrasol/libs_js/jquery.js',
        ),
        1 => 
        array (
          'file' => 'custom_folder/libs_js/jquery-ui.js',
        ),
        2 => 
        array (
          'file' => 'custom_folder/libs_js/HandlerCommonMethods.js',
        ),
        3 => 
        array (
          'file' => 'custom_folder/Modulos/Clientes/js/editview.js',
        ),
        4 => 
        array (
          'file' => 'modules/Accounts/Account.js',
        ),
      ),
  'form' => 
  array (
    'buttons' => 
    array (
      0 => array (
            'customCode' => '<input title="Guardar" accesskey="S"   type="button" name="Guardarcstm" value="Guardar" id="SAVE">',
          ),
      1 => 'CANCEL',
    ),
  ),
  'maxColumns' => '2',
  'widths' => 
  array (
    0 => 
    array (
      'label' => '10',
      'field' => '30',
    ),
    1 => 
    array (
      'label' => '10',
      'field' => '30',
    ),
  ),
  'useTabs' => false,
  'tabDefs' => 
  array (
    'LBL_ACCOUNT_INFORMATION' => 
    array (
      'newTab' => false,
      'panelDefault' => 'expanded',
    ),
    'LBL_PANEL_ADVANCED' => 
    array (
      'newTab' => false,
      'panelDefault' => 'expanded',
    ),
  ),
);
?>

The important part is where you are placing that code? Which filename, in which directory?

If your file is getting overwritten, it’s in the wrong place.

1 Like

the URL is the same directory I use to place the code on sugarcrm:

custom/modules/accounts/metadata/editviewdefs.php

I don’t know if the references should be in the same folder, actually the other files i’m refeering are out

Studio overwrites files in custom, normally under directories called “Ext”, but I don’t think it overwrites that particular path you gave.

So I don’t know what’s happening.

But I can suggest a way for you to find out with more information about what’s going on:

https://pgorod.github.io/Audit-File-Accesses/

1 Like

thank you so much

pgr

Thanks for your support