Getting a set of beans by conditions without SQL

sugarcrmdevelopers —  November 12, 2012 — 4 Comments

You’ll remember here on this very developer blog, we’ve been evangelizing developers to move away from using custom SQL statements to the built in bean methods provided by Sugar instead. One big hole was the ability to get a set of bean objects based on a condition, a common request by many developers. Fortunately our resident “how to do things in Sugar the right way guy” Jeff Bickart who is with Sugar Gold Partner NEPO Systems jumped in with mentioning the SugarBean::get_full_list() method. Although it is a bit ugly with how it’s parameters work, it definitely does exactly what we want and gets the job done.

So let’s look at this query a forums poster was looking on how to do with SQL only…

While on the surface this looks easier, it also doesn’t handle some of the Sugar-ism, such as setting the timestamps or generating a new record id. Let’s instead refactor this using bean methods, which makes it work much better…

While a bit more code, it’s more portable and definitely upgrade-safe.

4 responses to Getting a set of beans by conditions without SQL

  1. 

    Yes, get_full_list() is exactly what I needed Friday and couldn’t find. Thanks, John. I’m not sure how I missed Jeff’s comment on the other post, I thought I read through that whole section.

  2. 

    as I refer to the email field?

Trackbacks and Pingbacks:

  1. Scanning contacts for firstname - January 4, 2013

    […] […]

  2. performance of my code : retrieve_by_string_fields - February 8, 2013

    […] […]

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