Rules: how to programmatically set the bundle of an entity? For some tasks, rules requires to know the bundle of a given entity, the most obvious situation being when you need to set a field of a node and rules requires the type of node.

Normally you can solve this in the "condition" side of rules, where you can check that your entity is of a given bundle or that it has a specific field.
However there are situation where this approach is not possible, as when the entities derives from the result of an action, in my case they are loaded from a VBO view.
Hence how can you tell rules that a given list of entities - or a single entity - is of a given bundle, so I can use its specific fields ?
Actually, if you need to do something that's like an additional 'condition-then-action' within your rule's Action section, what you need is a Rules component!

You've loaded some entities in your action (perhaps in a loop) and now you need to apply a condition and action to those entities.  Here's the basic recipe for using components in your action section:


Go to /admin/config/workflow/rules/components to create a new rule component to run for each of the items in your loop (or for a single item you've gotten in your rule action). Click the 'Add new component' link at the top of the page
Select 'Rule' from the drop-down options, since this will be a component that contains both a condition and an action
Name the rule, and in the 'Variables' section, we have to let it know we're going to pass it a parameter to work with. In your case, this will be the entity you want to check.
Once you've named your components and named the parameter you'll pass it, the next screen looks very much like a regular rule.  Just set up the condition (make sure the entity is of type whatever) and the action (use the appropriate fields of that entity to do something).
Finally, save your component and call it in your original rule's action section (within the loop if you have one), passing it the entity to work with


Sorry that this is rather text-y.  I actually just recently answered a question about using rules components with commerce items in another question and included screenshots there, so see if you can use that as a reference too: https://stackoverflow.com/questions/17797285/drupal-commerce-order-object-extra-data/17843597#17843597

Let us know if rule components solve your issue!