When using the serial field token with the auto node title module, the node must be saved twice to pickup the serial value. Presumably this is because the serial field is the last thing that gets run so the token isn't populated for auto node title on the first save.

Others have tried to do this same thing using NID as discussed and patched here: http://drupal.org/node/194197

Can you have a look at that code to see if it will work with the serial field module like it does with NID?


I solved the problem in a roundabout way as explained here in comment 63, using the rules module:


Be careful using this technique if you have large numbers of existing nodes as this module adds a unique serial to all of them and adding the rule based technique to populate the autonodetitle eats up a lot of memory. I tried it with 1,500 nodes and it barfed after a few minutes even with a huge amount of allocated PHP memory.

I've added a bug report related to this as well: http://drupal.org/node/615470

Assigned:Unassigned» kirsh

Using rules, as you did, is probably the right solution.

This is clearly a bug, not a feature request. All other CCK fields I employ (even computed fields) are available in token form to be used in the Node Title on node creation. The rules approach is not the right solution, but an alternative solution given the serial CCK field is not functioning consistent with other CCK fields.

NID as well as serial field are not available as tokens because they don't exist until the form is saved. Same issue as referenced above. The problem lies in the node auto title module and the patch applies to it, not how and when NID is assigned by core.

I just want to know if the patch applied to node-auto-title will work with this field as well. As noted in that discussion it's apparently not quite ready for prime time, however.

After investigating this issue further, I have determined that this is in fact an issue with the Automatic Nodetitles module. It was actually a pretty simple fix, and I have posted my patch to that module here:


I hope that works, but the Serial module is almost unusable if you have large numbers of existing nodes because of this issue: http://drupal.org/node/615470

EDIT: Errant copy and paste. The link was wrong - now fixed.

suscribing here. i need this functionality.

You can get this working by following druplicate's (#1 in this thread) advice. If you don't want to read the post that he links to (specifically #63 in that thread), this is how to output a serial (from the Serial Field module) in automatically generated node titles.

0. Obviously you have to have the Serial Field module installed. You will also need to add a field for your content type that is of the type serial. Furthermore, you will need to install the Rules module.

1. On the list of content types, click Edit next to the content type in question. In the section Automatic title generation, write the pattern for your title. To get the serial field value, look at the Replacement patterns help box for a section called CCK serial tokens for a token with the help text "Serial field value (unique per node type)". Save the settings.

2. Go to admin/rules and create a rule with the following details:
- Event type: After saving new content
- Add Condition: Created content is SelectYourContentType
- Add Action: Execute custom PHP code (the PHP Filter module must be activated or else you won't see this option) and enter the following code in the text area:
Basically, the node will run Automatic Nodetitles' method auto_nodetitle_operations_update which updated the title of a certain node.

That should be it. Now, each time you create a new node of the type SelectYourContentType, the rule you just added will make sure that the Automatic Nodetitles module will update the title for the node so that your serial is actually added to the title.

NOTE. If you create a new node that has a serial field and get a warning that the table doesn't exist (which won't output the serial in the title, obviously), just re-install the Serial Field module. Make sure you first inactivate it, then the uninstall it and finally remove the serial directory on the server. Then install the module again.

Thanks rakeshakurathi - You were a life saver!

:) David

For me it works to make serial field part of Auto-Node-Title on my local windows server (xampp), but when i tried to make it work at the internet server, it doesn't save the serial to the title, only when I edit and save the node again. How can it be, that it works local but not on the server? Do I have to mind something else?

The issue with the Serial field is also affecting the Computed field's ability to grab the serial value, until the node is saved for a second time. An elaborate workaround using Rules isn't an option, IMHO. Can't Serial be modified to provide the value sooner so that it is available to other fields? We're pretty much just talking about an auto0incrementing field in a table, but maybe that's where the problem lies...

Version:6.x-1.0-rc1» 6.x-1.0
Status:Active» Needs review
new11.78 KB

Please review the attached fix that should solve the issues with both the auto node title and the computed field.

Note: update.php has to be run because this new version changes the schema.

Thanks for the update.

I got the following error when running update.php on this:

user warning: Unknown column 'i.type' in 'where clause' query: SELECT f.field_name FROM content_node_field f, content_node_field_instance i WHERE f.field_name = i.field_name AND f.type = 'serial' AND i.type = 'panel' in /home/holland/public_html/sites/all/modules/serial/serial.inc on line 49.

new11.94 KB

Attached an attempt to fix the update warning.

#14 worked perfectly for me. Thank you very much.

I concur #14 worked for me, much thanks!

#14 worked for me also. Thanks very much @kirsh. Any chance of releasing a new version of serial - to save others spending time unnecessarily on this issue? Cheers.

Confirming that #14 worked for me too, Thanks!

Status:Needs review» Reviewed & tested by the community

number #14 also work for me. seems it need to patch into new release.

change it to RTBC.

Version:6.x-1.0» 7.x-1.x-dev
Assigned:kirsh» Unassigned
Category:feature» bug
Status:Reviewed & tested by the community» Postponed (maintainer needs more info)

Sorry folks. I don't have time to sort through zip files. I need a patch file for this, and we'll need one for D7 first, before we can apply one for D6.

Is it even a problem in D7? If not, we can set it back to D6.

Version:7.x-1.x-dev» 6.x-1.0

I think that the zip from #14 can be published as is as version 6.x-1.1 and it would be better to do that before any other change.

I use it successfully for several months and apparently other users as well.

Actually the solution (of allocating the id earlier) is also applied in 7.x-1.1 (I fixed it in both D6 and D7).

Status:Postponed (maintainer needs more info)» Needs review
new11.3 KB

None of this needs to go into the D7 branch? Really? It looks like there are some things that could apply to both.

Here's the patch I came up with after diffing from the zip file. As I no longer have a D6 site for testing, I'll leave it to all of you to apply this to the latest D6 dev branch and test it. (I already synced it with 1.0 before making some minor changes.) If everyone's happy, I can commit it.

This is an issue in D7, too.

Version:6.x-1.0» 7.x-1.x-dev
Status:Needs review» Active

In that case, we'll need a D7 patch as well. I'll commit the D6 patch as soon as someone RTBCs it.

new5 KB

Attached patch for D7 includes the stuff from the D6 one that makes the serial value available earlier in hook_node_presave().

This means you can get around Auto Nodetitle's flaws and just call auto_nodetitle_set_title() from within your own module or build out the title yourself.

* Implements hook_node_presave().
function my_module_node_presave($node) {

Note that the D7 patch doesn't include the code for updating the serials for existing nodes using the batch API as I don't have time to go through that properly now.

After applying the patch, you need to run update.php to update the schema.

new6.19 KB

Dang. Botched the update. Here's another stab which also generates the serial in hook_node_presave if Auto Nodetitle module is enabled.

Status:Active» Needs review

Great, thanks. Not sure I'll have time to review this in the next little but, but hopefully someone will.

We should split this into several tasks anyway to keep things manageable and understandable. Don't worry about the batch API stuff; we can tackle that in a separate issue.

Hello, I just wanted to report that the patch from #26 works great for me!

sorry to hijack the thread again, but I found a problem with the patch at #26. Each time I restarted the mysql service on my server, new nodes for each content type would get reset to 1, having this way multiple nodes with the same serial for the very same content type.
I fixed it (at least I think/hope so) by restoring an if statement that was removed by the patch. Specifically in the serial.inc file around line 160 it should look like this:

if ($delete && ($sid % 10) == 0) {
     ->condition('nid', $nid, '<')

Is there a reason why if ($delete && ($sid % 10) == 0) was remove? Cause now it looks like it's working fine (I'll have to test a little bit more of course).

Thank you in advance,
Ioannis Panteleakis

Status:Needs review» Needs work

Fixing status.

Good catch, kmare!

The patch for D7 just apes the approach taken for D6 in serial.zip in #14 but restarting the database server also breaks that too so this definitely needs some work. Especially as the new approach dropped the node ID from the serial field tables. Sounds like this is still needed. I'll try to have another look at this soon.

Status:Needs work» Needs review
new9.7 KB

Only just had a chance to revisit this now. New patch restores the if statement. Also has some minor comment tweaks.

cool, thanx! I'll test as soon as I can and hopefully it'll get commited soon :)

Status:Needs review» Reviewed & tested by the community

sorry for not reporting back earlier. I just tested to the patch and it looks like it's working properly. Thanks for your patch!

Applied this patch, works for me, too. Good work!

Patch in #32 works for me also. Thanks for it!

I applied the patch in #32.
Works fine when creating a new node from scratch.

But I'm also using the module "node clone" (7.x-1.0-beta1).
With this patch, the cloned (duplicated) node gets the same serial number as the original one (= wrong, should be unique). Before applying the patch, cloning worked fine for me.

http://drupal.org/project/node_clone says:

The module provides two mechanisms to clone current content. The default pre-populates the form for adding a new node, but nothing is saved to the DB until that form is submitted. With the alternative save/edit method, a copy of the current node is saved to the DB, and then presented in the edit form. When using the save/edit mode, the admin can set whether a confirmation screen is required, and in all cases you can set whether to reset the publishing options on a per-content-type basis.

I've tested both ways; no difference.

PS: I'm new here (my 1st posting); hope I did everything right :-)

@ulrichk: I think the best way to handle this would be for Node Clone to provide a hook function that modules can implement in order to run their own code when the clone happens. So then Serial Field can then implement the hook by generating a new serial number instead of simply going with the copied one. I'd recommend creating two new issues, one in the Node Clone queue for the hook, and one here to implement it. (As this stuff is unrelated to this issue, it should be discussed elsewhere.)

Patch #32 Works fine here

Applying patch #32 to an already installed module causes "Unknown column uniqid" errors due to missing schema changes. You'll need to disable and uninstall the module, then apply the patch and re-enable.

Patch #32 works for me with Auto Node Title.
It also works with Auto Entity Label now...


Status:Reviewed & tested by the community» Fixed

Committed in b1c920e. I also added missing newlines at the end of the files. Thanks @kidrobot!

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

The patch from #32 worked like a charm, but as #40 already said you must reenable the module. Deleting and redownloading it however didnt work for me. Thats how I've done it:

- delete the serial folder in modules
- disable automatic nodetitles
- in your database, open the table system, search for an entry with name "serial" and delete the record
- download serial, the patch from #32 and apply the patch outside the drupal installation
- copy the patched serial folder in your modules folder, check the modules list and activate serial, then auto nodetitles
- use the serial token within auto nodetitles :)

thanks all!

Is the patch in #32 for D6 or D7?

Noob alert, sorry. Seems rediculous that this is so hard to acheive, on the other hand I at least understand the issues.

Ive just followed rakeshakurathi's recipe and it works fine with one provisio, which is that the Node creation message reads "*mynodetype* [node:field_serialno] has been created."

Do we need a rule to fire the update on the create node message as well?


It occured to me that what all I really wanted was a nicely formated node title, so I disabled Auto_NodeID and changed the action rule to

$node->title=sprintf('B%08d', [node:field_serialno]); where serialno is the name of my serial field.

Having disabled auto_nodeid, I have to set the title field to a temporary value {"XX") but thats ok because I'm testing and just wanted to take Auto_nodeid out of the equation.

What happens next is i get a node with Title =XX and a green "action message" (sorry, not sure what that is called) of B000000nn

Now what I was expecting was the node title to be set to B000000nn but it seems that node-> title is actually the green "action message" field???

Where am I going wrong?

Can we please have a release with this change included?

I don't see why not. I just released 7.x-1.3. Enjoy!