Set value for new field automatically based on another field I want to add a new date field to an existing content type, and set the new field automatically for existing nodes to be equal to another date field from that content type.

For example, if the new field is called 'Event date', and there is an existing field 'Publication Date', I want the 'Event date' field to contain the date from the 'Publication date' field for all existing nodes, without assigning each one manually.

Is this possible?
It is possible and the best way to do it is in a custom module. Here's how:


Assume you have a module called mymodule.
Inside mymodule.install create a function called mymodule_update_N where N is a number starting at 7100. See the API documentation for hook_update_N for details but this is what runs when you run update.php
Inside your mymodule_update_7100, load the nodes you want to act on and then iterate over them, setting your newly created field to the value from Event Date.


If you have a lot of nodes, you'll want to look to the Batch API system to batch the nodes one by one so you don't run out of PHP memory or run up against the timeout. If it's not a ton of nodes, you don't need to worry about that usually.

And last, but not least, you should use an EntityFieldQuery to get the nodes you want to act on.

Hope that helps. Good luck!