Serial number with Prefix or Suffix

Is there any way to add automated serial numbers with prefixes and suffixes in records?
  • Can you kindly describe the requirement? Any example, please?

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • What you need is first a running number, like the case number or bug number .

    This can be realized by an autoincrement field in your module. If the module does not have an autoincrement field you can create your own by a vardef extension, e.g. for opportunities in custom/Extension/modules/Opportunities/Ext/Vardefs/ with a file like this:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?php
    $dictionary['Opportunity']['fields']['opportunity_index'] =
    array (
    'name' => 'opportunity_index',
    'vname' => 'LBL_OPP_INDEX',
    'type' => 'int',
    'readonly' => true,
    'len' => 11,
    'required' => true,
    'auto_increment' => true,
    'unified_search' => true,
    'full_text_search' =>
    array (
    'boost' => 3,
    ),
    'comment' => 'Visual unique identifier',
    'duplicate_merge' => 'disabled',
    'disable_num_format' => true,
    'studio' =>
    array (
    'quickcreate' => false,
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    During QR&R you must make sure that all SQL commands for the opportunity table are exectuted in one SQL statement.

    Then you can create a custom field e.g. opportunity_number_c and add a prefix and/or suffix in a logic_hook after_save.to the running index e.g. like this:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    <?php
    class my_OpportunitiesHookImpl
    {
    public function afterSave($bean, $event, $arguments)
    {
    $prefix = "OPP#";
    $suffix = "_crm";
    //Prevent endless loop by checking alread set number:
    if ($bean->opportunity_number_c == "") {
    $number = $bean->opportunity_index;
    $number = "000000" . $number;
    $number = substr($number, -6);
    $opp = BeanFactory::getBean('Opportunities', $bean->id);
    $opp->opportunity_number_c = $prefix;
    $opp->opportunity_number_c .= $number;
    $opp->opportunity_number_c .= $suffix;
    $opp->save();
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    The format can be just as you want, you can even add some parte of the date to it.

    Harald Kuske
    Principal Solution Architect – Professional Services, EMEA
    hkuske@sugarcrm.com
    SugarCRM Deutschland GmbH

  • I just wanted to have auto-increment unique IDs like OPP-00001-NY in the modules.

    Below, has solved the problem I was having. 

    Bruce McIntyre

  • Appreciate it

    Bruce McIntyre