'Automatically create a user account via Rules' issue

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
skanarakis's picture

Hello,

I want to have in a Drupal 7 installation a new user account automatically created each time a new node of a certain content type gets created.

This content type contais an email field from where I will take the account email information. For the username, I just tried to create a combination of first and last name fields also available in the same content type.

I used Rules framework with the following configuration.

Event : After saving new content

Condition : Content is of type (and I choose my content type described above)

Action : Create a new entity
Entity Type -> User
Login Name -> [node:field-firstname]_[node:field-lastname]
Email -> [node:field_email]

The above fields are the ones of my content type.

To be honest, I cannot understand what is the meaning of the two last options (Variable Label and Variable Name) and I left them as they were automatically completed.

         Created Entity Variable Label -> Created entity
         Created Entity Variable Name -> entity_created

However, my simple rule does not work. No user account gets created and when I check the logs I can see two of them related to the failure.

  1. Unable to create entity user": Invalid data value given. Be sure it matches the required data type and format.
  2. Unable to evaluate action entity_create.

Can you please help me understand where is the error and what is the meaning of the created entity variable label and name configuration options?

Thanks
Stavros

Comments

Hi, for each element of a

igasi's picture

Hi, for each element of a rule is created a variable, it stores all the information in this case the user created entity, the label is to describe the variable.

Typically the variable that is created is then used to generate some other action within the same rule.

Can not be created because the data you enter is not valid, I recommend the following:
1. Download the module RulesDataTransforms.
2. You create your rule, defining the event and the condition that you put
3. Add an action that concatenates the first and last name, assign the variable name.
4. You create the action "Create a new entity" and select the variable name created in the field of e-mail your content type. and name your variable.
5. You create the action "Add user role", select your user variable you created and assign a role.
6. Finally activate the action has "Unblock a user", with the same user variable.

that's all, good luck

About Password

Jarviss's picture

Igasi may you tell how to set password for newly created user, so it could be sent to user email?

Hi Igasi, Thanks for the

skanarakis's picture

Hi Igasi,

Thanks for the information. I did a study in the concepts you mention about Rules and then I tried to take your approach. I could not do it at first, but then at some time, I re-wrote from scratch the first rule as I indicated in my first message and I was able to make it work !!

The bad thing is that I never understood what was the error and the user was never created at first time :(

Anyway, now I have another problem which is that I cannot find a way to assign a profile (for user accounts) from Profiles2 module to this newly created account. I have constructed two Profile2 profiles in my installation but I cannot see any way to connect such a profile via Rules with the newly created user.

I need such a connection because my third and last action must be data value insertions into the fields of these profiles from information taken from the event (on new node creation).

I tried to do it, but I get an error since the created user is NOT YET connected with a specific profile and it does not possess the field of the profile for which I am trying to change the value. So I guess I have to find a way to connect the profile first, but such a rule action is missing from Rules modules (and is neither offered by the Profiles2 module).

Do you have any idea from your experience how to overcome this problem?

Thanks
Stavros

Rules

Group organizers

Group categories

Categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week