1

My users have a field collection, called 'Score', with two fields: 'Date' and 'Points'. I'd like to add a new field collection item for all users at the end of the day, with the current date in 'Date' and their current userpoints in 'Points'.

I thought about using a scheduled rule, but I don't know how I can select something like 'all users'. Is this possible with Rules or is there another way to achieve this?


This question is part of How to create a line graph of the total user points on a profile page?.

1

Yes this is possible with Rules, if combined with Views Bulk Operations, as further detailed below ...

What you actually need to do is similar to what is shown in the video about Using VBO to load list of objects into Rules, starting from about 5:30, up to 11:30. Here is a summary of what is shown in this video (quote from the linked page):

  • You need a view that lists the entities you want to work on in Rules. Note that you don't need a display of the view – and it might even be better not to have one if you don't want the view to be displayed somewhere.
  • However, you need one bulk operations field. The type of bulk operations field determines what entity type will be sent to Rules. Note that you don't need any actions enabled for the field – it is enough that it is present.
  • You need a rule that, as an action, loads entities from a VBO. (This is available under the "Views bulk operations" group.) All view displays with at least one VBO field will be selectable.
  • The action provides a list of entities, that can be used just like other lists in Rules. Combine with loops, actions and Rules Scheduler to make awesomeness happen.

In your case you want to start from a VBO list of all the users you want to get processed. And for each user in the list you want the rules action to be as in your "scheduled rule", whatever that rule is actually supposed to do (instead of "remove sticky").

You want to pass the userid as a parameter also, similar to what is shown around 7:30 in that video also.

The Rules component that you create as described above, should then become the action to be performed by a rule that is triggered daily, via the Rules Scheduler, similar to what is shown in the video, starting from 11:30.

Should you need any other rules "conditions" (eg: only for selected roles), you can add them to the rules component you created.

Easy, no? Happy VBO-ing with Rules ... ( or Rules-ing with VBO if you prefer)!

| improve this answer | |
1

I'm not sure about rules but you could do that in a custom module with a little code:

$uids = db_query("SELECT uid FROM {users} WHERE status=1")->fetchCol();
$accounts = user_load_multiple($uids);
foreach($accounts as $account) {
    $edit['my_field'][LANGUAGE_NONE]['0']['value'] = 'my new value';
    user_save($account, $edit);
}
| improve this answer | |

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.