IMPORTANT NOTE: The following 
information is only valid for SugarCRM 6.5 and older. This information 
does not apply to newer versions of the product.
An OnDemand client of ours recently had a need for an  auto-incrementing number in SugarCRM. They had some fairly specific  requirements, including a reference to the current year, a “-“ and, of  course the auto-incrementing number that was comprised of 4 digits.
 A job of this nature was most certainly best handled by SugarLogic. In  my development environment, I first created the text field that would  increment in the Studio. From here, I found some helpful code on the  SugarForums from Eli Linder: http://www.sugarcrm.com/forums/showthread.php?t=39756.
I modified Eli’s code that he graciously put out on the forum to add  in my client’s specifications, including a starting point for the first  number:
Later in the code, I added in a check on the current year to be sure 
that it would add this in as the prefix. If you would like to see the 
full file please reply to this posting.
Now, the next step was to get this to act as an OnSave event when the
 Opportunity was initially saved. To do this, I added an after save 
statement to the logic_hooks.php file sitting in the 
custom/modules/Opportunities directory. Here’s how that looked:
$hook_array['after_save'] = Array(); $hook_array['after_save'][] =  Array(1, 'add_code',  'custom/modules/Opportunities/add_code_hook.php','add_code',  'add_code');
So, now all that’s left is to bundle it all up in your Development  environment through the studio and deploy to the OnDemand instance,  right? Close. In your saved .zip generated from exporting your  customizations, open up the manifest.php file and get ready to edit it.  You need to make sure your two custom files are directed to the right  spot in your OnDemand instance. Currently, they are not even included as  part of this manifest! (I was assured by SugarCRM technical support  that this would happen automatically in the next major release, 6.2.) I  added in the following to make sure it was copied from the right  location, and also ended up in the right location:
    22 =>     array (
      'from' => '/SugarModules/modules/Opportunities/logic_hooks.php',
      'to' => 'custom/modules/Opportunities/logic_hooks.php',
 ),
    23 =>     array (
      'from' => '/SugarModules/modules/Opportunities/add_code_hook.php',
      'to' => 'custom/modules/Opportunities/add_code_hook.php',
  )' 
 Before you knew it, my client was adding in Opportunities with a custom  tracking number that meant something to them in no time!: 
 
      
   
            Posted in: