[SOLVED][Drupal Rules] Increment a field value using rules

| | 1 min read

Many Drupal users have requested for a method to increment a field using rules in their Drupal site. If you are looking for a way to increment a field value using rules in your Drupal site then read on.

Here is how to do it. The following example is for incrementing a field value when a node is saved. Use this a template for doing it for your own custom field.

Rule:
Event: After saving new content

Conditions: Content is of type
- Data Selector: Node
- Value: [pick your content type(s)]

Action:
Fetch entity by id
-Value: User
-Data Selector: node:author:uid
-Provided variables: [leave as is or change if you want]
Execute custom PHP code
-$entity_fetched->"your_field"[LANGUAGE_NONE][0]['value'] = $entity_fetched->"your_field"[LANGUAGE_NONE][0]['value'] + 1;
Save Entity
-Data Selector: node:author

Hope that helps.

The easiest way to solve a Drupal issue is to hand it to the Drupal experts. Do you need professional help in building your Drupal site? We can provide a wide range of Drupal services to help you deploy your Drupal site easily and quickly. Get in touch with us to know more.