1)Create a content type with a multivalue field. I tried both text and select list.
2) create a rule that on saving new content with condition that the content type is the new content type
3 add loop with value of the multivalue field
4) add action under loop to create a new entity. Create new basic page. I used list-item as the title of the new node. Save rule.
5) create a node of new content type and fill in the multivalue field.
6) only the first item creates a new node.

Comments

fago’s picture

Title: create multiple entities from multivalue field » loops do not save changes of variables going out of scope
Component: Rules Core » Rules Engine

Oh, yes. The loop should care about saving all unsaved variables that go out of scope.
As interim workaround you can use the entity-save action to manually trigger the saving.

twistor’s picture

Status: Active » Needs work
StatusFileSize
new1.16 KB

This is probably all sorts of wrong, but it's working for me at the moment.

fago’s picture

Why are you removing the list-item? If it's changed it should be saved too.

We should make use of $state->cleanup() as this properly saves derived entities (by drilling down in the data selector) too.
For that to work we need to reset $state->save when cloning the state - that makes sense to me as that way cloned states can be safely used when a scope should not influence a parent scope and finish with cleanup.

videographics’s picture

Until this is fixed, we should document clearly that creating an entity within a loop requires the "Save entity" element with the "Force saving immediately" setting checked. (There. Maybe I just did it.) :-)