I have a content type which, among other things, have a field which contains a unique ID number (this number is used to connect the individual content to related information stored on paper).

When creating new entries I'd like to automatically generate this ID by finding the highest ID already present in the system, and calculating the next ID from that.

I have written a small module (using hook_menu()) which presents the user an interface for adding new content. How can I, from within this module, get the field_id values of my already existing content? (So that I can calculate which ID a new entry should have?)

Is there any PHP command which can be made to return an array containing all the field_ids from my content type?

Worth to know here is that the system is kinda small (500–1000 entries of my content type, at most). There will also only be a single person entering data at a time. Also, I'm using Drupal 7.

1 Answer 1


The easiest sulotion I can think about is to use Computed field module and the id field will be computed field.
Then, in the field read the last value using variable_get() and then update that value using variable_set().

  • Your answer led me in the right direction. – I ended up using variable_get() to set a #default_value in the render array for my form. (Though there was no need for the Computed field module.)
    – zrajm
    Commented Aug 28, 2013 at 3:26
  • Great! You are right there is no need in computed field :)
    – rreiss
    Commented Aug 28, 2013 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.