3

When a node (or user profile) is modified, is it possible to send an email notification only when a specified field is modified?

With the node I have no problem, but I cannot get it to work for a specific field.

2 Answers 2

3

You can use the Rules module for this. Here are some details about how to do so:

  • Rules Event: Before saving content.
  • Rules Condition: Compare the value of the specific field, for both the original value (before editing the field) and the (new) updated value, to verify if they are different.
  • Rules Condition: Send an eMail (which is typically implemented as a separate "Rules Component" (that is invoked as the Rules Action), whereas you pass the values like node id, current user, maybe author, etc. Within the Rules Component, you then compose the actual eMail (template) that you want to be eMailed. For an example of such a Rules component, have a look at my answer to "How can I set a reminder for a specific user to be triggered on a specific date?" (which includes such component in Rules export format also).

Should be straight forward to "develop" such rule, no (PHP) coding at all involved (only site building using admin UI).

8
  • Great @Pierre.Vriens , seems work as I expected but there is only two little issue: i) compare the body ([node-unchanged:body] with [node:body] ) not works. I receive a notification also if I not changed the text in the body. ii) with field collection the rule not works always as expected ([node:field-myfieldcolletion]). If I "Add another item" the compare works and I receive an email, instead if I edit an existing item (a field of the field collection) the comparison does not work.
    – kb8
    Commented Feb 9, 2016 at 23:58
  • Are you using a rules condition like "entity has field" (for those specific fields)? If not then their values will be process like blank or something. Commented Feb 10, 2016 at 0:03
  • Not but I not understand how it works. In "entity has field" I added "node" in "Entity" and "body" in "Field" but the problem persists. PS: in data selector I can't use "node:body:"
    – kb8
    Commented Feb 10, 2016 at 0:36
  • Add some screen: i64.tinypic.com/zybipz.jpg and oi63.tinypic.com/2u57sdi.jpg
    – kb8
    Commented Feb 10, 2016 at 0:43
  • For "Body" I have solved not with "entity has field" but adding the condition "AND" and after "NOT Text comparison" with "Parameter: Text: [node:body:value], Matching text: [node-unchanged:body:value]" (i64.tinypic.com/a4ydzn.jpg). For the field collection instead the problem persist. If I edit an existing field collection item (a field of the field collection) the comparison seems not work.
    – kb8
    Commented Feb 10, 2016 at 14:18
0

Have a look at hook_user_update. This hook is called when a user account (user profile?) is updated.

You might also want to look at hook_node_update. You will not be able to use the hook_node_update to be notified when your user accounts are updated, but on this page there is a comment about $node->original having the values of the $node before the update.

I have not tested this myself (should be a trivial excursive), but you may be lucky and find $account->original (or something similar) stores the original values of the user account.

It is then a simple matter of testing the old field value against the new one to see if a change occurred, and you can take appropriate action - like sending a mail.

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.