How to add JavaScript file in editview or detailview for any module in SugarCRM / SuiteCRM

It will be done by below steps only! Lets do this,

STEP 1 : Add a reference to the JavaScript file which will be needed for event binding.

Path for Edit View: custom/modules/<desired_module>/metadata/editviewdefs.php

<?php

$viewdefs['<desired_module>']['EditView']['templateMeta']['includes'] =
    array (
        array (
        'file' => 'custom/modules/<desired_module>/js/editview.js',
        ),
    );
?>

Path for Detail View: custom/modules/<desired_module>/metadata/detailviewdefs.php

<?php

$viewdefs['<desired_module>']['DetialView']['templateMeta']['includes'] =
    array (
        array (
        'file' => 'custom/modules/<desired_module>/js/detailview.js',
        ),
    );
?>

Step 2 : Add the JavaScript file you want to include into the location you referenced above(custom/modules/<desired_module>/js/editview.js) or (custom/modules/<desired_module>/js/detailview.js)

Step 3 : Write your custom function or validation in editview.js or detailview.js file.

Step 4 : Quick Repair, then hard refresh your browser. All Done !

Step 5 : Done! Refresh the page and start testing.

Note :

1. Read the comments in code carefully and replace the variables as asked.
2. Here, <desired_module> means the module name you see in the URL, for example, Contacts, Leads, Accounts, etc.
3. You may find the field names and its labels in Admin > Studio > <Your_module> > Fields > <Choose correct field> > Take 
Field Name and System Label.

Hope you find this blog post helpful.

Feel free to add comments and queries, that helps us to improve the quality of posts.

You can contact us at info@infotechbuddies.com

Thank you.

Spread the love

One thought on “How to add JavaScript file in editview or detailview for any module in SugarCRM / SuiteCRM

Leave a Reply

Your email address will not be published. Required fields are marked *