Search code examples
javascriptsugarcrmsuitecrm

Include .js file in SuiteCRM (v. >7) doesn't work


I'm new in SuiteCRM world. I'm trying to include a new .js file in a module but it seems doesn't work.

I seen that in Sugar version 6.5 for include a .js file it's enough to do something like that

$viewdefs[$module_name]['EditView']['templateMeta']['includes'] =
array (
    array (
        'file' => 'modules/demo_demo_form/demo.js',
    ),

); 

I also read that in the newer version(7>) it's changed the way to include a .js file.

I tried different ways* but seems doesn't work.

 $js_groupings[$module_name]['modules/demo_demo_form/demo.js'] = 
 'include/modules/demo_demo_form/demo.js';

Any suggestions?


Solution

  • I think my previous answer to another similar question will help you

    First, include your custom JS in the editviewdefs.php (example for Accounts module)

    'includes' => 
          array (
            0 => 
            array (
              'file' => 'modules/Accounts/Account.js',
              'file' => 'custom/modules/Accounts/myCustomFile.js',
            ),
          ),
    

    Create the custom JS file custom/modules/Accounts/myCustomFile.js .

    function yourCustomFunction(formElement){
      console.log(formElement); 
    }
    

    Then update the field you want to monitor for changes (contractsigned_c in the example) using the following code in the editviewdefs.php:

    array (
                'name' => 'contractsigned_c',
                'label' => 'LBL_CONTRACTSIGNED',
                'displayParams' =>
                 array (
                  'updateCallback' => 'yourCustomFunction(this)',
              ),
              ),
    

    Now do a Repair and Rebuild inside the Admin/Repair section and voilà it should work :)

    You can add the JS function on the function display() if you want, its the samething, the function will be called right after native combo update. It will look like this combo_contractsigned_c.update(); yourCustomFunction(this)