Creating an Autoincrement Field

Then, what do you recommend?

I had issues with that module after reaching the 99999 it just stopped counting because I set the format to be 00001, and thereā€™s no way to correct that (plus, I donā€™t like the zeros), Iā€™m just using a simple database auto increment field now

best regards

1 Like

Hello Mike

Please can you guide me on how to create the auto-increment field with the database so i can add that in my suitecrm. Please guide me through also how to use it on the studio at the particular modules I wanted to.

Thanks in advance.

Hi.
I do this easily from phpmyadmin.

  1. I select the field and select the Auto Increase option and save changes.
  2. If I want to select from which number I start the counter, I select the operations option and write the number.

see the attached image.

https://imgur.com/a/bYilwNG

I hope it works for you.

Thanks a lot for your answer. But after creating this autoincrement on the phpmyadmin, I wanted to know how I can use it on the studio. or the module that I wanted to use on. what should i do on the Suite Crm ?

Hello,

Just crate an integer field in your module by studio and add it to the detail view. Then make the changes in phpmyadmin.

its really simple ā€¦to great to be trueā€¦ i try whit my current sistem under suitecrm and ā€¦ tell you laterā€¦

I did this the other day for a custom module.

  1. Create a integer field in studio like normal.
  2. Edit the vardefs.php for the module and change the field so it has the values below
   '[fieldname]' =>
    array (
      'name' => '[fieldname]',
      'vname' => 'Number',
      'type' => 'int',
      'readonly' => true,
      'len' => 11,
      'auto_increment' => true,
      'disable_num_format' => true,
      'inline_edit' => false,
    ),
  1. Within the main ā€˜fieldsā€™ array in vardefs.php add an indices array (if it doesnā€™t exist)
 'indices' =>
  array (
    '[fieldindexname]' =>
    array (
      'name' => '[fieldindexname]',
      'type' => 'unique key',
      'fields' => array ( '[fieldname]')),
    ),
  1. Run a rebuild and repair

The only bug I found with this method is that rebuild/repair seems to infinitely say thereā€™s an consistency issue between the database and vardefs which seems to relate to the way the repair module checks if the field is a unique key.

Thanks

Urbanite

1 Like

Hola, Lo hice por el phpadmin y realmente fue muy fĆ”cil, no requiere de cĆ³digoā€¦

Muchas graciasā€¦

Just correcting aboveā€¦

type must be 'unique" , not ā€œunique keyā€

1 Like

Correct! My Bad.

For someone who need itā€¦ Exact and correct code which works for meā€¦

ā€˜auto_numberā€™ =>
array(
ā€˜nameā€™ => ā€˜auto_numberā€™,
ā€˜vnameā€™ => ā€˜Serial Noā€™,
ā€˜typeā€™ => ā€˜intā€™,
ā€˜lenā€™ => 11,
ā€˜requiredā€™=>true,
ā€˜auto_incrementā€™ => true,
),
shareeditdelete

ah, so the length of those bean ids can be shortened, they donā€™t have to look like nuclear launch codes?! :smiley:

You know, example: record=92a2bf72-237d-84ef-9ccd-5d2264f10161

Iā€™m looking to use a short unique id for vendor_id and profit_center in my Accounts module so I can do separate accounting reporting on budgets, revenues, profit, loss in different operations

Please can you specify where I can add this code to have the serial number

Check @urbanite response aboveā€¦

More info on Vardefs here: https://docs.suitecrm.com/developer/vardefs/

Hi,
A ready plugin is available without worrying to learn programming.

This plugin allows to add an Auto-increment field to any core module and custom module.

I want to Create one unique number field in Account module. This field is auto generate and alpha numeric. When account is created then this field value will auto genetare and must be unique.

I will suggest to use a combination of logichook and query if you are a programer.

First create a text field from studio. Then on a before_save logic hook, create a query that gets the last saved id and you create a process to increase it by on. Then you concatenate with your custom string and assign it to your custom field.

That will five you direct control on how to create your custom ID.

Thanks,

AlxGr

@jrmk, New topics please !