I created a rule this way:

Event: After saving new content
Condition: Content is of type 'Customer'

Actions:
1. Create new entity (Entity type 'User')
2. Create new entity (Entity type 'Node') using Author in action 1 (above).

My problem is that at some point between action 1 and 2 the user entity is available but not actually saved in the users table. I verified that by stopping (die) the script at that point and checking if the user is actually saved from the People's section. Because of this action 2 did not actually set the author to the user specified in action 1.

However, if I allow the rule to complete processing I could see that the user is actually saved in the database except that it's author is not set with the one in action 1. Again, that's because at some point between action 1 and 2, the user is not yet saved in DB.

I thought that the processing of actions in rules is synchronous which means it waits for the preceding action to finish before processing the next. Is the action processing asynchronous? How can I achieve rule's goal?

Comments

Mark Vincent Verallo’s picture

I'll answer my own question as I already solve it! Usually, the saving of newly created entities are done after all processing. Multiple saves are done in the end if there are newly created entities. So that you can use the new entity in other actions, you need to save it immediately. To do that, just add a new action "Save entity" and select the new entity you are creating.

mitchell’s picture

Priority: Major » Normal
Status: Active » Postponed (maintainer needs more info)

Thanks for debugging this. What can we do here, then? Is this a docs issue?

Mark Vincent Verallo’s picture

I think this is not mentioned in the docs but not sure.

TR’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Closed (works as designed)