1

I have created a user reference field on a node which lists (via Views) all the users the node author is related to in some way. If there is a better way to list users on node forms then I'm open to suggestions. In my particular case the field uses the autocomplete widget with the Views list, but a select list widget could also be used.

I would like to be able to execute a Rule on the user that is selected in the autocomplete/list by the node author. At the moment I am using the Button Field to trigger the Rule execution but I'm not sure how to get the Rule to apply to the specific chosen user. Some ideas are flagging the user when they are selected or doing a textual comparison between the autocomplete text and existing usernames. I have also tried the Relation module but still can't figure out how to get the selection recognized in Rules.

1

It sounds to me like you need to fetch the user as an entity in Rules, if you have multiple users use a loop. After this you should be able to apply the relevant action. Here is a stab at the Rule (note, this is untested but should point you in the right direction):

Event
- (Whatever trigger/s you want here)

Condition
- Entity is of type: Node
- Entity has field: (pick the user reference field here)

Action
- Loop(for multiple users)
- (Final action you want to take place. Add the new variable here)

Hope that makes sense. See how you go with this and let me know.

|improve this answer|||||
  • Thank you very much for this, I thought I'd never get a response. I've tried the above method but when I get to the last step and try to enter my token "variable" in the value field, it always tries to append "entity host" on the end and gives me a wrong parameter error when I try to save the action. Could this be because I'm using a field collection instead of a node? – Sammie Aug 31 '12 at 14:03
  • I managed to fix the problem in my comment above, I was drilling too far down in the tokens list. Also I found that using "Fetch Entity" in the action isn't needed because the field is already referenced through the conditions before. The problem though is that the Rule is calling the field before the new value in it is actually saved, which returns no result. If the node is first saved and then the Rule is triggered, it works perfectly. I tried adding a "Save entity" action before the final action is executed on the selected user but that didn't help. Any suggestions? – Sammie Sep 2 '12 at 9:36
  • Ok, I updated the answer. You should be able to save the node via Rules and execute your final action after. Maybe you will need to Flag the node and then use a second Rule. I would suggest opening a new question for the saving part though. – David Gurran 82 Sep 3 '12 at 16:00

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.