Very useful module. Would be nice to allow a starting number, like 1,000.

Also, if I use this id in a token for auto node title, how does the node get saved?

In order to do this atomically I'm assuming the id is assigned at node save.

If so would the auto node title module assign this id properly at save?

When I added this field to an existing content type I got a zillion of this error, I think one for each of the existing nodes:

user warning: Duplicate entry '353' for key 2 query: INSERT INTO serial_condo_building_field_serial_id (nid) VALUES(353) in /usr/local/www/apache22/data/sites/all/modules/serial/serial.inc on line 89.

Comments

druplicate’s picture

How is this module different from the Type Local NID module other than being a CCK field?

Per this issue: http://drupal.org/node/398116

Is it truly atomic, ie does it mimic the way Drupal assigns NIDs?

kirsh’s picture

> Would be nice to allow a starting number, like 1,000.

Might be supported in future versions. Meanwhile you may try using ComputedField + Serial.

> Also, if I use this id in a token for auto node title, how does the node get saved?

I didn't try it with node title, but a serial field is not different than any other field - save is managed by CCK.

> When I added this field to an existing content type I got a zillion of this error

This might be a bug. It didn't happen when I added a serial field to an existing content type.

> How is this module different from the Type Local NID module other than being a CCK field?

The atomic allocation.

> Is it truly atomic, ie does it mimic the way Drupal assigns NIDs?

Yes, it is atomic. Both Drupal nid and Serial field (but not Type Local nids) use an underlying serial database field.

druplicate’s picture

Thanks.

I was curious about how the CCK node gets saved because of all this discussion:

http://drupal.org/node/194197

Seems like it's a big deal and I wanted to know how or if this module addresses it, especially with respect to tokens.

kirsh’s picture

Assigned: Unassigned » kirsh
Status: Active » Closed (fixed)
Architeck’s picture

I'll second the request "Would be nice to allow a starting number, like 1,000"

Can you provide an example using ComputedField + Serial?

Thanks, Great module, I have also applied the patch from http://drupal.org/node/606250#comment-2528212 it's a nice little addition.

kirsh’s picture

Install ComputedField. First create a serial field and then a computed field.

Set the computed code:
$node_field[0]['value'] = $node->field_serial[0]['value'] + 1000;
where field_serial is the internal name of the serial field.
You will have to adjust the code if you are using the prefix/suffix patch.
But actually, if you are using a computed field - you do not need that patch, you can add the suffix/prefix here.

Make sure "Store using the database settings below" is checked (otherwise the computed field is not accessible in Views) and set the data type as int.

If you already have nodes with serial values you will have to save them again to get a computed field value.

nicholas.alipaz’s picture

Actually, even easier than adding an additional field to the database, and of course this depends on how one would like to use these fields. You can do something like the following using cck custom formatters (just import this definition and enable for your field's display setting):

/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  return array(
    'mymodule_formatter_invoice_number' => array(
      'arguments' => array('element' => NULL),
    ),
  );
}

/**
 * Implements hook_field_formatter_info().
 */
function mymodule_field_formatter_info() {
  return array(
    'invoice_number' => array(
      'label' => 'Invoice Number',
      'description' => t('A formatted invoice number for use on serial fields.'),
      'field types' => array('serial'),
      'multiple values' => CONTENT_HANDLE_CORE,
    ),
  );
}

function theme_mymodule_formatter_invoice_number($element) {
  $value = $element['#item']['value'] + 10100;
  $value = str_pad($value, 6, "0", STR_PAD_LEFT);
  return "ST-$value";
}

--
Los Angeles Web Design and development for Drupal.

Rix-1’s picture

I set the code to:

$node_field[0]['value'] = $node->field_serial[0]['value'] + 1000;

and changed 'field_serial' to my internal field name 'field_photo_ref' so my code is:

$node_field[0]['value'] = $node->field_photo_ref[0]['value'] + 1000;

but i get the following error:
* Notice: Undefined variable: node in eval() (line 1 of /..../sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).
* Notice: Trying to get property of non-object in eval() (line 1 of /..../sites/all/modules/computed_field/computed_field.module(439) : eval()'d code).

What am I doing wrong?

[Drupal 7]

Rix-1’s picture

Also, does this mean that everytime I save it, it will add 1,000 to the serial field? So the serial number will change every time I update the page? :o(

mel-miller’s picture

Version: 6.x-1.0-beta1 » 7.x-1.2

@rix

Did you ever find a solution to those errors?

Rix-1’s picture

Nope - abandoned the project.

alexander.sibert’s picture

I search a solution for my URLs attachment. I installed Serial and Computed field. Now i want to produce following number and use it in URLs via Token.

http://domain.tld/000014
http://domain.tld/000015
http://domain.tld/000114
http://domain.tld/002214

You see what i mean.

imunk’s picture

its a great module but since it has'nt a prefix or sufix number in the module it not really usefull, but it will be a great module if you put the starting or ending number on it..

seanenroute’s picture

Hi, for those using D7 the Computed code to add a 1000 (to make it a 4 digit code) is:

$entity_field[0]['value'] = $entity->field_serial[LANGUAGE_NONE][0]['value'] + 1000;