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
  • 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);
      }
    }

     }
Children
No Data