How to create unique id for CCK field automatically

Vnaraj - January 12, 2007 - 07:42

I create a new content type using CCK. I call it "Case List" consisting of these below fields.

Case Title: [ Fill out ]
Case ID: 1262 (This field is new node id for reference,
displayed only, can't edit)
Date: [ Fill out ]
Case Detail: [ Fill out ]
Reported by: [ Fill out ]
Contact Phone: [ Fill out ]

What I want to do is to have Drupal autogenerate unique Case ID number and saved in this Case ID field everytime we click "Case List" to create new content.

I don't know how to implement this. Can anyone help please.

Auto Increment

drupal-id.com - January 30, 2007 - 02:41

If "Case ID" only integer field then you can edit the table field (using Database Editor like PHPMySQL) and enable Auto Increment for "Create ID" field. Unfortunately, this "Case ID" will displayed after you save your content.

What table name to look at

Vnaraj - February 1, 2007 - 07:32

Thank you, I got an idea. But what table name should I look at to enable field type to autoincrement?

Is that the new content type that I create? Let's say "Case", so I should edit table named node_case, then field_case_id. Pls correct me if I'm wrong.

The table name is using this

drupal-id.com - February 7, 2007 - 09:32

The table name is using this format: node_contenttype, mean your "Case" become "node_case".
Just open the node_case table and you will find the correct field.

Can't set a CCK field as autoincrement

suoko - May 6, 2008 - 14:57

phpmyadmin says
#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

Why not just use the node

ceejayoz - May 7, 2008 - 20:07

Why not just use the node ID?

Node ID

lhernon - June 3, 2009 - 17:08

I am trying to figure this out too. I tried to use Auto Node Title, using node ID [nid] for the title, but unfortunately, the node doesn't have an id until it is created, so my title field remained blank.

I'd love to find a way to automatically generate a unique ID as a title.

_

WorldFallz - June 3, 2009 - 17:50

Use auto_nodetitle to generate any dummy title and hide it. Then add a cck field for the real title using the http://drupal.org/project/type_local_nids module or a computed field with the code you want to use.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Getting NID

kentr - June 23, 2009 - 21:20

Check out this Computed Field snippet for getting the NID to use inside the field: http://drupal.org/node/149232

 
 

Drupal is a registered trademark of Dries Buytaert.