How to add a Autoincrement field for Account and Contacts

I was trying to create a unique record id for accounts and contacts with prefix + auto increment numbering. It seems the studio or module builder doesn’t come with this option. Please advise how this can be done. Thanks!

Hi there,

To do this, don’t add the field via Studio, add a new file in custom/Extension/modules/yourmodule/Ext/Vardefs e.g. autoincrement.php with the following :


<?php
	 $dictionary['YOUR_MODULE']['fields']['NAME_OF_AUTO_INC_FIELD'] =  array(
            'name' => 'NAME_OF_AUTO_INC_FIELD',
            'vname' => 'LBL_LABEL_OF_AUTO_INC_FIELD',
            'type' => 'int',
            'readonly' => true,
            'len' => 11,
            'auto_increment' => true,
           'disable_num_format' => true,
        );
?>

and also add unique index for the field in that file


<?php
	 $dictionary['YOUR_MODULE']['indices']['NAME_FOR_INDEX'] = array(
            'name' => 'NAME_FOR_INDEX',
            'type' => 'unique',
            'fields' => array('NAME_OF_AUTO_INC_FIELD'),
        );
?>

Run a Quick Rebuild and Repair in Admin -> Repair and execute the changes.

Thanks,

Will.

2 Likes

Hi Will,
Do I need to add this to every module that require the auto increment field?
Cheers,
Kent

Hi there,

Yes, I believe so. There may be more refined ways to do this but it would require considerable development effort.

Thanks,

Will.

1 Like

How about the Prefix? E.g. Account module with running number as ACC-1002, Contact module with running number as CON-2001.

i have the solution im runing something similar.
im using this http://www.sugarforge.org/frs/download.php/9387/dtg_sugar_autoincrement-0.2-beta.zip

more info http://www.sugarforge.org/projects/autoincrement/

1 Like

Hi,
I tried to install this in SuiteCRM but getting error at the end of installation and it never works so far.
Error:

100%

Display Log
Rebuilding ActionViewMap…
Rebuilding ActionFileMap…
Rebuilding ActionReMap…
Rebuilding Administration…
Rebuilding EntryPointRegistry…
Rebuilding Extensions…
Rebuilding FileAccessControlMap…
Rebuilding Layoutdefs…
Rebuilding GlobalLinks…
Rebuilding LogicHooks…
Rebuilding Menus…
Rebuilding Include…
Rebuilding ScheduledTasks…
Rebuilding UserPage…
Rebuilding Utils…
Rebuilding Vardefs…
Rebuilding JSGroupings…
Rebuilding Actions…
Database failure. Please refer to sugarcrm.log for details.

1 Like

I would check your sugarcrm.log for the details of why this failed.

if you can find the fatal error in the sugarcrm.log we might beable to point you in the right direction to fix this.

Ian.

07/31/14 01:24:30 [7688][1][FATAL] Retrieving record by id config:6373e754-f42b-4e15-9415-53d9faa16cda found Query Failed: SELECT config.* FROM config WHERE config.id = ‘6373e754-f42b-4e15-9415-53d9faa16cda’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 01:37:59 [7688][1][FATAL] Retrieving record by id config:7c1e00fc-c00d-9100-e7ac-53da002425b5 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘7c1e00fc-c00d-9100-e7ac-53da002425b5’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 01:46:25 [7688][1][FATAL] Retrieving record by id config:372c4805-eb07-79a0-93a0-53da02cf239c found Query Failed: SELECT config.* FROM config WHERE config.id = ‘372c4805-eb07-79a0-93a0-53da02cf239c’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 01:59:55 [7688][1][FATAL] Retrieving record by id config:ee38292b-a5b3-0ae3-49a2-53da0535bbb1 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘ee38292b-a5b3-0ae3-49a2-53da0535bbb1’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 02:05:37 [7688][1][FATAL] Retrieving record by id config:bebb7419-7a7a-4504-79c4-53da0697ee04 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘bebb7419-7a7a-4504-79c4-53da0697ee04’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 02:14:21 [7688][1][FATAL] Retrieving record by id config:5af925f1-2f08-f951-38e6-53da08855cd5 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘5af925f1-2f08-f951-38e6-53da08855cd5’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 02:16:07 [7688][1][FATAL] Retrieving record by id config:47485331-3e76-b6e7-cfa4-53da0965af10 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘47485331-3e76-b6e7-cfa4-53da0965af10’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 19:46:30 [7688][1][FATAL] Retrieving record by id config:e1406d24-5a32-1a2e-f35f-53daff336ed6 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘e1406d24-5a32-1a2e-f35f-53daff336ed6’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
07/31/14 20:23:21 [7688][9196fdcf-ceb7-0fe1-80ae-53db07ba0f42][FATAL] Retrieving record by id config:667ed5b6-8e50-292e-5cc9-53db08e489c3 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘667ed5b6-8e50-292e-5cc9-53db08e489c3’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
08/01/14 00:06:33 [7688][9196fdcf-ceb7-0fe1-80ae-53db07ba0f42][FATAL] Retrieving record by id config:86eb033a-4390-a4cd-f10b-53db3ca5aa3f found Query Failed: SELECT config.* FROM config WHERE config.id = ‘86eb033a-4390-a4cd-f10b-53db3ca5aa3f’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’
08/01/14 01:04:24 [7688][9196fdcf-ceb7-0fe1-80ae-53db07ba0f42][FATAL] Retrieving record by id config:b754781b-bef2-bd01-54a4-53db4a07fb82 found Query Failed: SELECT config.* FROM config WHERE config.id = ‘b754781b-bef2-bd01-54a4-53db4a07fb82’ AND config.deleted=0 LIMIT 0,1: MySQL error 1054: Unknown column ‘config.id’ in ‘where clause’

If you have a look at this link

http://suitecrm.com/index.php?option=com_kunena&view=topic&Itemid=1136&catid=7&id=1641

This appears to be a bug with SuiteCRM however it should not stop the install process so a repair and rebuild should finish the install of the module and the module should work after that ?

Ian.

1 Like

Brilliant! It works right after the rapir and rebuild! Great! Thanks!

yes with this componet you need to Rebuild.

While duplicating the data, autoincrement field value is not incrementing.

and what happend if you open and saved that duplicate data (lead, account etc)

Same number generating.

Thanks

tried this and doesn’t work.

Try this Module. It allows a prefix, year, dash, postscript

https://github.com/shauncollopy/dtg-autoincrement

yeah thanks i tried that, all i get upon attempting to load the module is ZIP Error(0): Status(0): Arhive(upload://dtg-autoincrement-master.zip): Directory(/tmp/rrXCV3)

The module didn’t even load or appear in the module list

Not sure what happened to that version. Thought I used it a few months ago.
Just tested this version on a new install and works good.

2 Likes

Well thanks for supplying that version, unfortunately while i was able to load it, the numbers do not auto increment.

Kindly see attached screen shot: