1

I want to copy a geofield to another geofield in the same content type.

  1. I created a Rule where I "Set Data Value" and with that I copy the data of one geofield into the other. Actually I created two actions one for longitude and latitude.
  2. This action is triggered when "After updating existing content".
  3. I used VBO to parse through my nodes therefore the trigger to be fired and geofield data to be copied.

Nothing happens. I get two errors in error log saying:

Unable to evaluate action data_set.
Unable to modify data "node:field-business-location...

I tried to expose the fields to rules by "Entity has field" condition but doesn't work either.

What am I doing wrong.

PS: There is also an option of "Create Geofield values from Lat/Lon but I don't see how I can copy data from one Geofield to another Geofield like this.

My Rule Export

{ "rules_copy_geolocation_data" : {

"LABEL" : "Copy geolocation data - Destinations",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "node_update--destination" : { "bundle" : "destination" } },
"IF" : [
  { "entity_is_of_bundle" : {
      "entity" : [ "node" ],
      "type" : "node",
      "bundle" : { "value" : { "destination" : "destination" } }
    }
  },
  { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_destination_location" } },
  { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_business_location" } }
],
"DO" : [
  { "data_set" : {
      "data" : [ "node:field-business-location:lat" ],
      "value" : [ "node:field-destination-location:lat" ]
    }
  },
  { "data_set" : {
      "data" : [ "node:field-business-location:lon" ],
      "value" : [ "node:field-destination-location:lon" ]
    }
  }
]   } }
  • @Pierre.Vriens Just did. – pierostz Sep 23 '16 at 13:45
0

Debugging is the art of taking away all possible reasons that may cause your issue ... Read on for more details to find out which one it might be, and how to possibly solve it.

Option 1: After updating actually happens before updating

Have a look at the issue about "After updating existing content" runs before content is saved, about an event which is a variation of your event here, and somehow explains that "after saving something" actually happens "before saving something". Therefor I'm about sure this is not a bug, but simply how the Rules module works.

A possible compromise to avoid these kind of issues, is to transform what you're trying to do into a Rules Component, so that your original Rule "schedules the execution" (using the Rules Scheduler sub-module) of that Rules Component. For example after only a few seconds or minutes if your cron job runs frequent enough (otherwise it'll be next time cron runs). This compromise will ensure that, at the time the Rules component is executed, the entity is for sure saved (so that can't be the reason anymore then why things don't work as expected).

Option 2: Add an extra Rules Action 'Save Entity'

Another cause of possible confusion is within the Rules module, where sometimes it gets tricky to "save entities". So possibly adding an appropriate "save entity" action (after the 2 Rules Actions you already have) may also help (if nothing else helps).

Option 3: Rules debugging

Rules is great, but sometimes also tough to debug if things don't work as you'd expect. There are some typical facilities to do such debugging (further detailed below), but a Keep-It-Super-Simple technique I often use, is my BINGO-trick. A sample of such rule can be found in my answer to "Which Rules condition can be used to email a user when an admin updates their profile?". Stupid, but simple and efficient (I think). If tis doesn't help, then there are typically 2 ways of more advanced debugging:

  • Rules Evaluation Log

    Within the Rules settings, experiment a bit with the debugging facilities that come with the rules module. At least have a look at the "Rules Evaluation Log" (to check that the Rules logic being executed, actually matches what you expect that logic to be).

  • Rules Action to display a value (using devel)

    You may also want to (temporary) enable the Devel module, so that you can (temporary) add a Rules Action like "Display a value".

    Obviously, make sure that there are no Rules Conditions that would prevent the Rules Action(s) from being executed (if needed temporary remove such Rules Conditions).

For way more details about these 2 variations, refer to Rules debugging, as explained in the answer to "How can I display the value of a variable inside a condition?".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.