By Vnaraj on
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.
Comments
Auto Increment
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
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
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
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
Why not just use the node ID?
Node ID
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.
_
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.
Getting NID
Check out this Computed Field snippet for getting the NID to use inside the field: http://drupal.org/node/149232
Module for auto incrementing
This newish module is probably the easiest way to go:
http://drupal.org/project/serial
There appears to be decent support and new improvements are in the works:
http://drupal.org/node/606250
Serial module is a great
Serial module is a great module but is still a bit buggy.
A solution is to download computed field module http://drupal.org/project/computed_field and run a PHP code in the created field. Check out the readme.txt that comes with computed field for more details.
PHP code snippet:
Drupal in the Amazon Jungle