I've finally figured out how to see data from a views row in a rule. I'm using this rule for updated user event. I'm grabbing data from the location module (street, in this example). I can do fine basing conditions on a row of data at saved time but I'm unable to get rules to see the data in the view of the account before it was changed. Even thought i'm basing and connecting my parameters to the unchanged account when linking the component to the rule.

Here is the exported code of my test rule and the component I am using as an action.

rule:
{ "rules_test_rule_message" : {
"LABEL" : "Test Rule message",
"PLUGIN" : "reaction rule",
"WEIGHT" : "-2",
"REQUIRES" : [ "rules" ],
"ON" : [ "user_update" ],
"DO" : [
{ "component_rules_test_address_component" : { "preupdated" : [ "account-unchanged" ] } }
]
}
}

Component:
{ "rules_test_address_component" : {
"LABEL" : "test address component",
"PLUGIN" : "rule set",
"REQUIRES" : [ "views_rules", "rules" ],
"USES VARIABLES" : { "preupdated" : { "label" : "preupdated", "type" : "user" } },
"RULES" : [
{ "RULE" : {
"PROVIDE" : { "list_street" : { "presaved_street" : "presaved street" } },
"DO" : [
{ "views_rules_collect_rows" : {
"USING" : {
"display" : "user_profile:views_rules_3",
"param_view_user" : [ "preupdated:uid" ]
},
"PROVIDE" : { "list_street" : { "presaved_street" : "presaved street" } }
}
}
],
"LABEL" : "Fetched Location"
}
},
{ "RULE" : {
"IF" : [ { "NOT data_is_empty" : { "data" : [ "presaved-street:0" ] } } ],
"DO" : [ { "drupal_message" : { "message" : "successful rule" } } ],
"LABEL" : "test message"
}
}
]
}
}

Comments

zhangtaihao’s picture

Yes, well, unfortunately triggering on the "After updating an existing user account" event means using a view would get the user details after the account has been updated, i.e. the view would return the current location value at the point the action is evaluated.

That event provides the unchanged object strictly inside Rules, so I'd recommend sticking to Rules (and not using Views) to deal with old values. To make use of values on the user object, use conditions like "Entity has field" to make custom fields available for use inside Rules.

Of course, you could also trigger the rule on "Before saving a user account".

IWasBornToWin’s picture

Wow, thank you so much for a quick response. I am not certain I understand the solution. I do understand explanation about rules and unchanged data. This has been tricky because Location module doesn't implement with rules so I'm having to use views rules.

Are you saying I could find the location value just with rules by using "Entity has field" condition? I will try to conceptualize how to do this. I am basically trying to know when a user adds OR subtracts a street address. I've got the adding part...but subtracting is where I need to know if there was data there prior to saving.

Thank you again for a great module and your quick reply.

IWasBornToWin’s picture

This continues to be tricky. I just tried a condition, "Entity has field" but the location module for users does not show up as entity, as a field for user entity, or anywhere inside rules that I know of - except your views rule display.

zhangtaihao’s picture

Unfortunately I think Location has simply never really been upgraded for Drupal 7. The only reason I mentioned the "Entity has field" was I assumed you've used a field to store location data (via something like Profile2 to extend user details). However, if you've simply enabled the User Locations module, I'm afraid that doesn't integrate with anything.

Are you stuck with the Location module? If you're not, I'd recommend reconsidering the primary focus of the location info. If it's for precisely geolocated data about a user, I'd look into Geofield + OpenLayers for describing geographical features and representing them on maps. If it's for collecting addresses, I'd look into the Address Field module. There's also Geocoder for tying together address information and geographical data.

IWasBornToWin’s picture

Thank you. I tried locations for user fields but it doesn't allow individual field usge on views; ie - street, city, distance, etc.

I will look at your suggestions. My primary reason for location is to determine distance (in miles) between users.

Thank you again.

zhangtaihao’s picture

Status: Active » Fixed

Well, if you do use fields, it will give you a great deal of flexibility in Rules.

I also maintain another module to expedite rule configuration: Conditional Rules

IWasBornToWin’s picture

FYI - not sure if you know this, but even location used as a field in users wont show up in rules. I'm going to look at the Geo mods you suggested but I did look at them before....I simply need something that will tell me the distance between two different addresses. I'll look again. Thanks for your help.

zhangtaihao’s picture

I assume you tried "Entity has field" with the field?

IWasBornToWin’s picture

Yes, I tried. I created an address field of location type for users. Wasn't able to see anything in rules. I think I will use Addressfield and one of the geo modules you suggested. It looks like there are many different ways for me to determine the distance between two different addresses.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.