Pages

Tuesday, February 24, 2015

SugarCRM Customization: Custom Blur Event

One of the ideas that I regularly try to convey when talking about the customization capabilities of the Sugar 7 framework relates to leveraging JavaScript wherever possible. This is especially true for projects where our objective is to upgrade heavily customized versions of Sugar up to version 7.x.

In the pre-7.x world, some customizations that can now be implemented natively via the Sugar 7.x framework used to require the use of SugarLogic functionality or inclusion of third party JavaScript libraries. The case of SugarLogic can be particularly problematic if one utilizes a large number of such customizations, as it might imply the execution of additional server side code. The greater the number of these type of customizations and the greater the potential to introduce performance problems. This is also true for logic hooks. For example, a hook that automatically converts the last name field to upper case upon a record being saved.

If we step back and analyze these customizations, we would likely find that some could be implemented via JavaScript. Doing so would in turn offload some of the server load to the client -- likely helping correct performance problems. The latter example of the logic hook upper casing the last name field is a good case in point. 

Suppose we wanted to convert such a customization to implement it through JavaScript instead of using a logic hook. How would we do that? 

The general idea would be to use a standard onBlur() event, tied to the last_name field of a module such as Contacts and then automatically updating the content of that same field when focus is lost.

As it turns out, the Sugar 7.x framework makes this a very easy task. The code for making such a customization is found below:



I hope you find it helpful!

7 comments:

  1. Hey man,
    I'm try using your code in Lead module, but not work. what's wrong with code ?

    I'm using sugarcrm 7.6

    ReplyDelete
    Replies
    1. The module shouldn't matter, so long as you've placed the file in the proper directory.

      Without seeing your code and/or knowing where you placed it, it is a bit difficult to provide further assistance.

      Delete
  2. Hi Angel,
    What if I want to run the default duplicate checker of SugarCRM 7 manually from the function doUpperLast?
    is it achievable?

    ReplyDelete
  3. Hi Angel,

    Great thing to know ,

    I used it on Subpanel-list.js and it worked like a charm

    Can you please let me know , how we can pass parameter to this function?

    Thanks,

    Ketan B

    ReplyDelete
  4. Everybody does not purchase an expensive DSLR blur camera to capture/snap the auto blur image. But don’t worry we solve this problem freely

    ReplyDelete

Your comments, feedback and suggestions are welcome, but please refrain from using offensive language and/or berating others. Thank you in advance.