W-Systems joins SugarCRM! Read Blog

Who Closed this Sales Opportunity?

by Eric Wikman on January 15, 2009

3 minute read

In my previous post, I described how you can use business logic hooks to protect your customizations in SugarCRM. Here is how we did it for one client.

The Use Case

A W-Systems client needed to know when a sales rep closed a sales opportunity so that a report could be built to show all opportunities that were closed during a certain time period. The client also needed to know which rep closed the opportunity. The client wanted to be able to modify the opportunity record in the future, but not the date that the opportunity was closed or the name of the rep who closed it. Once the opportunity was closed, the closing date and rep were not to be changed. Neither were they to be set or modified manually; they needed to be set by the system automatically.

The Solution

Using the SugarCRM Studio, we created two new fields. One is called Closed Date and the other is called Closed Rep. Both fields were added to the detail layout of the Opportunities module, but not to the edit layout. This way, people can see the values of these fields but cannot edit them. Since the fields were added via Studio, they can be reported in the Reports module just like any other field.

After creating the two new fields, we added a business logic hook to the event called before_save. The before_save event runs every time a user clicks the save button on the edit layout of a given module. The code added to that event checks to see if the status is changing from a non-closed state to a closed state. If the field is changing in that manner, then the system populates the closed date field with the current timestamp and sets the closed rep field to whatever user was changing the status to closed.

Now the client can see who closed each sales opportunity and when, and because we incorporated the needed logic via a business logic hook, the customization will always be protected whenever SugarCRM issues a change or upgrade.

This is one case where the solution is truly as simple as it sounds.

Do you have a technical question about SugarCRM? Post your question in a comment and I'll try to answer it here. Alternatively, Contact Us and we'll respond as soon as possible.