![]() |
Source: photosteve101/Flickr |
Thursday, April 14, 2011
Logic Hooks: OnDemand Installations
Friday, March 30, 2012
Logic Hooks: Lead History Transfer
Tuesday, October 11, 2011
SugarCRM Logic Hooks: Unintended Loops
Friday, July 20, 2012
Logic Hooks: Odds and Ends
Thursday, February 18, 2010
SugarCRM Logic Hook: Proper Casing Fields
One of the biggest challenges with a database application such as SugarCRM is ensuring that data is entered in a uniform manner by its various users. The use of drop down and multi-select fields helps address this challenge quite well, but said field types cannot be used in all places.
A good example of where they cannot be used is the Last Name field on a Contact entry. However, at the same time, it would be nice to be able to enforce some uniformity in the field's values, for example, ensure that names are being entered in proper case.
This need provides us with a great opportunity to once again highlight the power of logic hooks. In our example, the uniformity we want to introduce is the proper casing of the text entered into the Last Name field. Thus, values that are typed in as "doe" are automatically corrected and saved to the database as "Doe."
A logic hook is the perfect solution as it is transparent to the user and easily extended to support other fields.
Lets take a look at how we can accomplish the above...
Wednesday, July 27, 2011
Logic Hooks: Truncating Displayed Values
At first glance, the reasons why someone would want to do this are not always readily apparent. However, consider the scenario where one uses a text area field (e.g. description) on a module and one wishes to display that field on the subpanel.
The process of including the field on the subpanel is easily accomplished via Studio, but over time, an issue not initially apparent usually starts to surface.
Because a text area field can hold large amounts of text, it is possible for a user to populate the field with a number of pages worth of data. That on its own is not a problem. However, displaying that on a ListView, of which a subpanel is a good example, usually causes undesired display problems, as demonstrated by the image that follows (click to enlarge):
The issue at hand is that the Description field with the longer text value makes the subpanel appear a bit odd, to the point that the additional columns that are part of the view appear to the extreme right of the screen.
So how do we solve this? Easily, via a logic hook. Let us take a look at how we do so.
Saturday, March 17, 2012
SugarCRM Cookbook: Adding Related Records
Monday, June 1, 2009
Simple SugarCRM Logic Hook Example
- Modifying values on a record before it is saved to the database
- Updating other databases based on actions performed within SugarCRM
- Conditional sending of e-mail messages
$hook_version = 1;
$hook_array = Array();
$hook_array['before_save'][] = Array(1, 'assignUser', 'custom/modules/Cases/autoUserAssignment.php', 'UserAssignment', 'updateCase');
Make sure to save the file to the [sugar]/custom/modules/Cases directory.
The logic_hooks.php file described above provides the parameters necessary for SugarCRM to know not only when the custom code should execute, but also where the code can be found.
Notice the reference to the file autoUserAssignment.php. That is the file that SugarCRM will examine for the custom code that needs to be executed when the appropriate conditions are met.
Create a PHP file by that name and store it in the [sugar]/custom/modules/Cases directory.
Add the following to said file:
<?php
class UserAssignment {
function updateCase(&$bean, $event, $arguments)
{
//Query ACCOUNTS table for assigned_user_id value of parent Account
$case_id = $bean->id;
$acct_id = $bean->account_id;
$query = "SELECT accts.assigned_user_id FROM accounts accts ";
$query .= "WHERE accts.id = '$acct_id' LIMIT 1";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc($results);
$user_id = $row['assigned_user_id'];
//Change assigned_user_id value on Case
$bean->assigned_user_id = $user_id;
}
}
?>
That should do it!
From now on, whenever a user clicks Save on a Case, SugarCRM will automatically set the Assigned To value to match that of the related Account.
Tuesday, November 24, 2009
SugarCRM Customization: Custom Workflow E-mails
Within the scope of SugarCRM, the topic usually comes up in relation to the automation of some aspect of a business process, such as alerting a user when a record within the database has been assigned to them. SugarCRM includes such a feature out of the box, but what if one wanted a bit more flexibility?
Suppose we encounter the following scenario:
Our deployment uses the Leads module to track and qualify potential customers. Leads enter the system via two different ways: manual entry and web-to-lead.
Entries are required to have an e-mail address or they are not considered valid as our internal process use it for communications and other purposes. Whenever a new lead is entered, it is automatically assigned to a specific user, who in turn receives an e-mail alerting them of the new record. However, we want to expand this functionality to also automatically send a generic "Welcome/Thank You For Your Interest" message to the Lead itself.
How do we go about accomplishing the above?
Monday, July 15, 2019
SugarCRM Customization: Sending Emails - New and Improved
As some of you might have already correctly surmised, a number of changes have occurred to Sugar since those blog entries were written. One of the major additions to Sugar since then has been SugarBPM, which itself includes an email template engine.
Let us revisit the original problem of programmatically sending emails and examine how we can accomplish the same via SugarBPM. This time around, we will assume our intention is to send an email about an Account record.
We will first need to create the email template containing the content to be sent. Said template can be static or, if desired, may also include references to specific fields from the target module, to be parsed at send time. For our example, we may wish to make an email template that reads as follows:
ACME Corporation
123 Main Street
Some City, CA 90000
...but rather than typing specific values, we would instead insert references to the corresponding fields that contain the values we want from the Accounts module -- our Target Module. That would make the template much more flexible.
Note that the process of creating such a template for SugarBPM differs than that for a standard email template. To create an email template for SugarBPM, select Process Email Templates from the Sugar navigation bar and then click Create. Further information pertaining to this process can be found here:
https://support.sugarcrm.com/Documentation/Sugar_Versions/9.0/Ent/Administration_Guide/SugarBPM/Process_Email_Templates/index.html
Sunday, November 7, 2010
My Two Rules of Logic Hooks
Regardless of the reason or the intended purpose of the logic hook, there are a couple of rules that I've learned one should always adhere to in order to avoid problems.
Curious about what they are? Keep reading.
Tuesday, February 24, 2015
SugarCRM Customization: Custom Blur Event
Thursday, January 6, 2011
January is Logic Hooks Month
According to the stats for this blog, logic hooks are a popular subject amongst visitors. As such, I figure the topic would be a great way to kick off an idea of mine that I have been tossing around for a bit.
Going forward, I will select a topic of interest, or theme, on a monthly basis. The objective: to discuss the topic at hand in further depth throughout the month, with other posts sprinkled in between for variety.
However, this idea can only work with your assistance.
To help, simply reply to the post announcing the month's topic (e.g. this post) and suggest a facet of said topic for discussion. For example, perhaps you have been wanting to build a logic hook to execute an SQL query, but are unsure about how to get started. Simply share your scenario within the comments area.
In turn, I will select one of the suggestions on a weekly basis and provide a detailed post discussing the process involved in addressing the issue.
Now, while all suggestions are welcome, there are some rules to consider:
1. For obvious reasons, I cannot create a detailed post for every suggestion, but if time permits, I will tackle more than 1 per week.
2. Please be as clear as possible in your description of your scenario. If the description is not clear, I will not consider it.
3. Do not post sample code or the like. A clear description of the goal will suffice.
4. Some scenarios may require very specific configurations, such as custom modules, etc. I will not be able to create mirror environments for all cases, but my response will include sufficient guidance to fulfill the vast majority (if not all) of your goal.
5. Suggestions on themes for upcoming months are welcome and highly encouraged.
Thanks and now lets have the suggestions relating to logic hooks (in the comments section)!
Friday, September 9, 2011
Commentary: SugarCRM OnDemand
Thursday, June 9, 2011
SugarCRM Customization: Workflow Emails with Templates
It is certainly possible and that is exactly what we will cover in this post.
To save ourselves some time, we will simply modify the script from the previous post and change the relevant portions so as to cause it to use an e-mail template instead of the file based template it previously used. But before that, we need to create the e-mail template.
Create your e-mail template as you would any other, following these steps:
1. Select Emails > Create Email Template within SugarCRM
2. Compose your message and click Save when done
Next, we need the ID of the email template you just created. This will allow us to leverage it within the script, giving us our desired result.
To retrieve the ID:
1. Select Emails > View Email Templates
2. Click on the email template you just created
3. Copy the content from the address field in your web browser to your clipboard
4. Paste the content to Notepad or other format where it can be easily inspected
Once pasted, you should find that the address field contains something similar to the following:
&record=9940c799-359b-f2fb-2943-4c619dfc696f
The portion to the right of the equal sign is what we will need.
With the preliminary work out of the way, we can proceed to modify the script that sends the message. If you want to see the original script, take a look at the original post.