4

I have created a content type called Tasks that helps me track things I need to do on my site. I am trying to create a rule that when some content is published, a new task item is created reminding me to do some follow up work.

I created a rule that when the new content is published, a new task item is created. I did this by adding Create a new entity to the Actions section. I can give the item a title and set the author, but I can't figure out how to update the other fields in the new Tasks item.

Can this be done using rules or do I have to write PHP code to accomplish this?

2 Answers 2

1

In Rules you have to add those fields as conditions - "Entity has x,y,z field" - then they will become available for your actions

5
  • So I started doing this, but I don't understand what I have to put in for Data Selector.
    – Robbert
    Commented Jan 22, 2014 at 3:46
  • Add condition "Entity Has field" and select the field. Save, you will be prompted to add the Data Selector. The dropdown will contain something like: site:... (Site information) node (created content) node:... (created content) drill down to the most specific selector without a colon at the end. You probably want node (created content) then Save Commented Jan 22, 2014 at 19:01
  • see drupal.org/node/1300042 for documentation for data selection Commented Jan 22, 2014 at 19:09
  • I added the Entity has field Parameter: Entity: [node], Field: body condition. But my Create new entity action does not have any option to populate the body field of the new entity. Any suggestions other than php code?
    – David R.
    Commented Apr 4, 2016 at 19:42
  • Oh, you have to use the set a data value action. Huh.
    – David R.
    Commented Apr 4, 2016 at 19:50
1

To "update the other fields in the new Tasks item" (as in your question), you can perfectly do this by extending the current list of Rules Actions you already have to "Create an entity" (of type node).

Here is a typical set/sequence of Rules Actions to get the job done, say for also updating 3 other fields of the node to be created:

  • Create a new entity (Entity type = Node), which is the Rules Action you already must have in place to create your Task.
  • Set a data value for field1 of the created entity (pick whatever value for it that fits).
  • Set a data value for field2 of the created entity (pick whatever value for it that fits).
  • Set a data value for field3 of the created entity (pick whatever value for it that fits).
  • Save the entity (make sure to use "Force saving immediately").

For an example of a rule (in Rules export format) with a similar set of Rules Actions (for only 1 such field), refer to my answer to "Set value on newly created node using Rules".

Obviously, for this there is no need for any custom PHP code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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