How to automatically modify a field after saving content? I have posted this question on drupal.org (via a comment titled "field modification triggered by saving action"), but I realized that the thread is more than five years old. So I reproduce here the question made there:

field modification triggered by saving action

I need to modify a field, but this change has to be triggered when saving the term and it depends on the value of another field, let me explain ...

term


field 1: filled with options A/B/C
field 2: &lt;info&gt;random_name


I save and if value in


Field 1 is A, then value in Field 2 must change to "Source: random_name"
Field 1 is B, then value in Field 2 must change to "Destination: random_name"
Field 1 is C, then value in Field 2 must change to "Product: random_name"


Note that the label &lt;info&gt; is the one that must change.
You can use the Rules module to get this logic implemented. Have a look at my answer to "How to set the values of some fields depending on the value of a list box?".

The rule shown there uses these fields:


a selection list field with machine name field_optionlist (corresponds to your field 1).
a text field with machine name field_free_format_text (corresponds to your field 2).


If you adapt the machine names in that rule (in Rules export format) to the names from your 2 fields, should be straight forward to further tune (customize) it to also match the values as in your case.

However, to make this to work with only 1 rule (instead of writing 3 rules, ie one for each possible value of field 1, so one for "A", one for "B" and one for "C"), you also need the "Conditional Rules module. That way you could expand the prototype to say dozens of different possible values. For an example using the Rules Conditional module (for which there is not a lot of docu available), refer to my answer to the question "How to prevent a node being saved when using the Rules module?".

Best practice advise: the more you start using the Rules module, the more you should try to group rules together using the Rules Conditional module. Just to keep the entire set of rules manage-able (eg to have related business logic shown on a single Rule UI screen). A good sample of how easy it is to end up with a lot of rules, is what you can see in the Answers module (current 7.x-4.x-rc2 version):


It comes with 12 separated rules (not using the Rules Conditional module).
By using Rules Conditional, those 12 could be reduced to only 4 (possibly even less).