HOWTO: Use a custom query in a dashlet

bsoremsugar —  June 17, 2011 — 2 Comments

Editor’s Note: This tip comes from a forums post by our very prolific community member, Jason Eggers ( probably better known by his forums, Twitter, and IRC handle ‘eggsurplus’ ). He’s contributed several bug fixes and features to SugarCRM over the years, including the dashlet auto-refresh feature in the recently released Sugar 6.2. He’s also built several add-on modules for Sugar; you can check them out at https://www.eggsurplus.com/store/.

I recently ran into an issue where I did not want the default query for a dashlet to be used. The biggest issue was the table_name.deleted = 0 condition that was being added to the where clause by default. Looking through the code there is no option to remove this. So to trick Sugar into giving the desired query I had to do the following:

1. Open the dashlet file. This one was a custom module so it was modules/CustomModule/Dashlets/CustomModuleDashlet/CustomModuleDashlet.php
2. Add a buildWhere function to override the DashletGeneric buildWhere:

3. Override/add a process function:

This then creates the following where clause:

Which turns the custom_module.deleted condition into a string. That along with the 1=1 will cause it to always return true making it return all rows as desired.

 

 

2 responses to HOWTO: Use a custom query in a dashlet

  1. 

    and how you use this?

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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