How do you auto increment an "ID" field for every opportunity record?

We are trying to create a field in Opportunities that automatically assigns an auto-increment value to each new Opportunity.  This is with an On-Demand instance, so we have no access to code.

Any suggestions would be greatly appreciated!

Many thanks, James.
Parents Reply Children
  • Here is a before_save logic hook on Opportunities that works in 6.x:

    if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
    class Save_Opportunity
    {
    function newOpportunity($bean, $event, $arguments)
    {
          //custom field z_opportunity_id_c is an auto-increment field in Opportunities
      $start = $bean->z_opportunity_id_c;
         if ($start != 0)
         { return; }

    //The auto-increment seed/value in this example is stored/held in the Users module
    // custom field z_opportunity_id_c, for a user with some IM Name

      $opp = BeanFactory::getBean('Users');
      $where = "users.messenger_id='some_id_name'";
      $opp_list = $opp->get_full_list("", $where);
      if(! isset($opp_list))
      {  
       $GLOBALS['log']->fatal("IM name not found");
      }
      else 
      {
         $the_opp=$opp_list[0];
         $start =$the_opp->z_opportunity_id_c;
         $bean->z_opportunity_id_c = $start+1;
    // auto-increment for next save
         $the_opp->z_opportunity_id_c = $start+1;
         $the_opp->save(FALSE);
      }
    }

     }
  • Hi James,

    You can always request the sugar support to have a copy of your OD instance. They will provide you with a zip of the files and db for your instance.  With these you can deploy it on your local machine. You can always use this local copy to create your customizations.
    If your customization is fine you might want to package it then upload and install it to your OD instance.
    With regards to your auto increment field on the opportunity. You can create an int field then add on the vardef of the field 'auto_increment' => true
  • Or just follow this tutorial (works for both, Sugar6 and Sugar7 ):
    http://www.sugarcrmcolombia.com/produccion/wiki/?p=29