Conditional Formatting on Cases List view and Dashlets

sugarcrmdevelopers —  October 15, 2012 — 8 Comments

Editor’s Note: This blog post comes from an excellent forums thread created by community member Francescas. While often I quote or reference blog posts and provide solutions, having one this spot on and very upgrade-safe is one our whole developer community should build from, so I felt re-posting it here will bring that attention to it ( with some minor editiorial and code changes for clarity and to reflect best practices ).

Do you have any great tips or code like this? If so, I invite you to be a guest blogger on this blog; just email me at for more information. And big thanks to Francescas for this spot on forums thread!

We wanted to get something on Cases Dashlets and Cases List view to make certain statuses/conditions stand out.

Here is what we achieved:


Name:  dashlet.png Views: 1 Size:  43.1 KB

List View:

Name:  list_view.png Views: 1 Size:  52.0 KB

And Here is how I did it – It may not be the best way, but it works:

I added a non-db field to Cases, this will contain my bullet image in <mysugar>/custom/Extension/modules/Cases/Ext/Vardefs/custom_var.ext.php

Ran Repair Rebuild.

In <mysugar>/custom/modules/Cases/metadata/listviewdefs.php, I added customCode on the Status field to display the non-db field contents next to the status in the list view:

I then added a process_record logic_hook in <mysugar>/custom/Extension/modules/Cases/Ext/LogicHooks/formatCaseField.php to set the non-db field based on values for each record. This logic hook executes for each row of the list view (which is also used for the dashlet)

The conditional formatting script sets the non-db field for each row. The “title” in the img makes it so that when the user hovers on the colored bullet they get an explanation of what that color in, just in case they forgot or don’t know.

NOTE: I had to use a new Cases bean because the $bean in the logic hook only contains the fields that are displayed in the listviewdefs.php, not hidden fields like my
if I used $bean->case_number_of_interactions_c then I would have gotten NULL on all values because that field is not included in my list view. By using the $bean id to retrieve a copy of the full bean (which I called $c) I can use any field in the cases or cases_cstm table

For the images in <mysugar>/custom/themes, I created a bullets subidrectory and loaded some bullet images

To get the same bullets in the Dashlet I copied the My Cases Dashlet directory to
and added my non-db column with no title (so it takes up less space) and not sortable, I didn’t want the little arrows to appear either and it wouldn’t make sense to sort by an image

Admin->Repair->Rebuild Sugar Dashlets
Admin->Repair> Quick Repair/Rebuild for good measure

8 responses to Conditional Formatting on Cases List view and Dashlets


    See meeting.php for how do this one step without logic_hooks..much neater


      True, less failure points. However, it is best to avoid customizing the core bean directly. There are ways to safely extend the bean but there are limitations there to keep in mind if you plan on mass distributing your solution.

      Francescas has shared a very elegant way of doing this without having to mess with customizing beans.


        No, I disagree..for custom modules there is no problem. One could also extend the vardefs to call a function and return HTML or set it in view.list.php…but what we have here is an example of how it should not be done…as you said yourself way too many break points


          I don’t see where you disagree. I stated that editing a core bean is best avoided. Custom beans are fair game. Completely agree with you.

          I understand your other points, but there are many factors to consider when trying to decide which route to take. Because, as you allude to, there are many ways to do the same thing in SugarCRM. The factors that pertain to you really drive the best route to take. In some cases, being able to upgrade a solution easily is way more important than following general programming best practices. In fact, it may go against general best practices but could be considered a SugarCRM best practice (a whole different conversation).

          In Francesca’s case, he may not want to utilize a custom view since there isn’t a way to do so safely that guarantees it won’t be overwritten by some other installable module. Maybe he doesn’t believe returning formatted HTML from a vardef is MVC compatible.

          I still say this solution is elegant in respects to SugarCRM development and that is what is important in this development space. It may not go with standard development best practices but it does the job well in regards to how SugarCRM works.


            I disagree that it is an elegant solution and don’t believe it fits
            Sugar CRM best practice (which should not differ from coding best
            practice) I am not sure why you are defending this so vociferously. As I
            have mentioned, there are other, cleaner implementations which can help
            Francesca understand her options better…not just a simple ‘it works
            therefore it must be great’ approach


              Defending is not the right word. Encouraging people to share solutions is more like it. Instead of tearing people down, which discourages others from sharing, I feel it is better to promote people sharing what has worked for them. Yes, it is good to point out better ways of going at things, but do so without being a jerk about it while providing a solid alternative. I have yet to see a better way presented here from you that is upgrade safe and avoids using solutions that could conflict with other installed modules. I’m sure there may be, but that is the difference between being helpful with pointing out better solutions and being just a negative Nancy.


      agc, it would be more helpful to point to the function within Meeting.php. There are more than 20 functions. We have to weed through each one to see what youre talking about.


    It would have been better if you could provide some screenshots for newbies.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s