Tags

CRM & Technology Management


Sales and Marketing Advisor


Sign Up For the Newsletter

Login

Welcome to the Technology Advisors Blog!!

Technology Advisors CRM and Technical Information
May 27
2011

Creating OnChange and OnSave events in SugarCRM

Posted by: Justin Kuehlthau in MyBlog

Tagged in: SugarCRM

Justin Kuehlthau

When I started digging into customizing SugarCRM I often found it difficult to follow along with suggested solutions.  I mainly searched the SugarCRM forums for help on specific questions.  Most of the time I could find sample code but not the information on how to use it.  In this blog post I'll show how to create a very basic onload and onchange event for a module.  The specific example I will work towards is implementing a Subtype dropdown based on the Type dropdown in the Cases module.

The below post assumes you have a basic knowledge of SugarCRM, the studio, upgrade safe customizations and the custom directory. If you have any questions feel free to ask in the comments section.

The first step is to have an action fire when the edit view of the module is loaded (onload event) and when the Type dropdown is changed (onchange event). In my example I've already created the Subtype dropdown field and added it to the Cases module:

Customizing SugarCRM

Because I configured the Cases Edit View Layout in the Studio, the custom file I need to edit now exists at:
..custommodulesCasesmetadataeditviewdefs.php

Note that this file may not look very clean if you open it in a general text editor such as Notepad. You can use the free source code editor and Notepad replacement Notepad++ for a better experience, http://notepad-plus-plus.org/.

For the onload event I need to add to the 'templateMeta' array in editviewdefs.php:
'javascript' => '<script type="text/javascript"> onload=alert("OnLoad"); </script>',

I also need to add the onchange event to my type dropdown. To do this I add the 'displayParams' property to the Type field:

       4 =>
       array (
         0 =>
         array (
           'name' => 'type',
           'label' => 'LBL_TYPE',
           'displayParams' =>
           array (
             'javascript' => 'onchange=alert("OnChange");',
           ),
         ),
       ),

In this case, 4 is the row number and 0 is the only field on that row. Depending on your layout and the name of your field this may be different.

Making these changes to the editviewdefs.php file should cause a popup window to show when you edit a Case and when you change the Case's type. In my next post, I will look at having the events call a custom JavaScript function.

Hits: 2022
Comments (0)Add Comment

Write comment
smaller | bigger

security code
Write the displayed characters


busy