3

I'm trying to make a rule so that when a node of content type X is created, a node of content type Y is also created and is automatically populated with a nodereference field to the nid of content type X that was created. Then the user should be redirected to the edit form of the node of content type Y that they just created.

My rules configuration looks like this right now:

Event: After saving new content

Condition: Content is of type X

Actions:

  • Create a new entity of content type Y
  • Set a data value: set the node reference field on new node of content type Y nid of new node of content type X
  • Page redirect: URL: [entity-created:edit-url]

Everything works as expected except the redirect (which I thought would be the easiest part). Both nodes get created and the node reference field is set correctly. But I get a page not found error with the following messages:

Notice: Undefined property: stdClass::$nid in node_tokens() (line 112 of /web/xxxxxx/www/modules/node/node.tokens.inc).

"content type X" "title of new content of type x" was successfully created

The requested page "/node//edit" could not be found.

I've also tried node/[entity-created:nid]/edit for the page redirect. Same exact problem. I have no idea why it's not plugging in the nid of the new node of content type Y in between node/*/edit.

3

Basically you need to create another event right after "create entity" which immediately saves the new entity before you move on to the redirect rule.

See also http://groups.drupal.org/node/204558#comment-688188.

| improve this answer | |
1

After setting the data value, also choose the action "Save entity" action and remove the page redirect action which is not yet needed.

Next

Create another rule that has:

Event "After Saving new Content"

Condition: content of type y

Action: Page redirect -> [node:edit-url]

When you are done with both rules, you can set the weights of the rules so that one runs before the other. So set your rule to weight: -2 and then set the new rule to weight: -1 and save them. At the bottom of the page click on settings and you will see a drop down of values for the weights.

| improve this answer | |
  • Seems similar to the other answer except that it's a separate rule. Wouldn't the fact that it's a new rule though mean that this always happens whenever saying content of type y? That wouldn't be desirable in this case. – Jay Feb 12 '12 at 7:13
  • Yes it happens only after creating a new content of type y, not after editing a content of type y. If you want to also create a content of type y without using content type x then your better solution is to use the link above. But if you only use content type x to create content type y then then my answer should be okay too. – N dube Feb 12 '12 at 11:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.