I am trying to change a node author after saving a new node of a certain kind.
It seams to be impossible.
The concept is as follows:
I have a membership content type called Medlem. This content type have fields with first name, last name, email and member number.
When a new Medlem is created a new user should be created with the user name first-name last-name and also with a field with the member number.
When I want to change the author of the created node to the new user name.

I have made a message to see that th parameters I am using seams to bee the right and it seams so. But than I shall do the switch of the author it fails and I get some error message that says that it is a duplicate.
Here is my Rule:

Event: After saving a new entity of type Medlem
No condition
Action: Create a new entity
- Entity type: User
- User name: [node:field-f-rnamn] [node:field-efternamn]
- Mail [node:field-epost]
Action: Set a data value
- Selected data: entity_created:field-medlemsnr
- Value [node:field_medlems_nr]
Action: Set a data value
- Selected data: entity_created:roles:1
- Value: Medlem
Action: Fetch entity by id
- Entity type: Node
-Identifier: node:nid
Action: Show a message on the site
- node:title [node:title]
- node:author [node:author]
- entity-fetched:author [entity-fetched:author]
- User: [entity_created:name]
Action: Set a data value
- Selected data: entity-fetched:author
- Value: entity-created

Really hope fore some help on this.

Comments

chrotto’s picture

Title: Change node autor » Change node author
chrotto’s picture

Issue summary: View changes
chrotto’s picture

Issue summary: View changes
chrotto’s picture

Here are the Rules debugg information with the last action skiped:
Rules debug information:
" Reacting on event Efter sparande av nytt innehåll.
0 ms Reacting on event Efter sparande av nytt innehåll.
7.848 ms Evaluating conditions of rule Ny medlemsregistrering. [edit]
7.861 ms AND evaluated to TRUE.
" Rule Ny medlemsregistrering fires. [edit]
0 ms Rule Ny medlemsregistrering fires.
4.695 ms Evaluating the action entity_create. [edit]
5.068 ms Added the provided variable entity_created of type user [edit]
8.402 ms Evaluating the action data_set. [edit]
13.196 ms Evaluating the action data_set. [edit]
17.175 ms Evaluating the action drupal_message. [edit]
17.585 ms Evaluating the action entity_fetch. [edit]
36.741 ms Added the provided variable entity_fetched of type node [edit]
40.871 ms Evaluating the action drupal_message. [edit]
41.077 ms Rule Ny medlemsregistrering has fired.
49.034 ms Saved entity_created of type user.
77.276 ms Finished reacting on event Efter sparande av nytt innehåll.

chrotto’s picture

Issue summary: View changes
chrotto’s picture

And here is the errormessage that shows when the last action is included:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '281-1-taxonomy_access_role' for key 'PRIMARY': INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5), (:db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11), (:db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17), (:db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20, :db_insert_placeholder_21, :db_insert_placeholder_22, :db_insert_placeholder_23), (:db_insert_placeholder_24, :db_insert_placeholder_25, :db_insert_placeholder_26, :db_insert_placeholder_27, :db_insert_placeholder_28, :db_insert_placeholder_29); Array ( [:db_insert_placeholder_0] => 281 [:db_insert_placeholder_1] => taxonomy_access_role [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 281 [:db_insert_placeholder_7] => taxonomy_access_role [:db_insert_placeholder_8] => 2 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 281 [:db_insert_placeholder_13] => taxonomy_access_role [:db_insert_placeholder_14] => 4 [:db_insert_placeholder_15] => 1 [:db_insert_placeholder_16] => 1 [:db_insert_placeholder_17] => 1 [:db_insert_placeholder_18] => 281 [:db_insert_placeholder_19] => taxonomy_access_role [:db_insert_placeholder_20] => 5 [:db_insert_placeholder_21] => 1 [:db_insert_placeholder_22] => 0 [:db_insert_placeholder_23] => 0 [:db_insert_placeholder_24] => 281 [:db_insert_placeholder_25] => taxonomy_access_role [:db_insert_placeholder_26] => 7 [:db_insert_placeholder_27] => 1 [:db_insert_placeholder_28] => 0 [:db_insert_placeholder_29] => 0 ) i node_access_write_grants() (rad 3548 av /home/longstay/sites/hbf_3/modules/node/node.module).

TR’s picture

Status: Active » Closed (duplicate)