2

I have a rule that clones a node once it's flagged. I can set certain parameters for this newly cloned node but not all. I read in other posts that you have to use a conditional rule to identify what the node type is of that cloned node and then you have access to all the fields. But again not to "all" fields.

I want to set the cloned node text field "student name" to the author's first name, a text field on the user's profile. Many fields from the flagging user's profile are available but not all.

1

It looks like you already found "a" solution for your own question, but since you don't really understand your own solution, and because IMO there is an easier to understand solution, consider the below alternative ...

Step 1: Create a Rules Component

Create a Rules Component (of type "action set") like so:

  • Parameter "node_to_update" and "node_author".
  • Rules Action = "show message".

Here is a prototype of such Rules Component (in rules export format, use the Rules UI to import it in your site):

{ "rules_update_cloned_node" : {
    "LABEL" : "Update cloned node",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "USES VARIABLES" : {
      "node_to_update" : { "label" : "Node to be updated", "type" : "node" },
      "node_author" : { "label" : "Node author", "type" : "user" }
    },
    "ACTION SET" : [
      { "drupal_message" : { "message" : "The field firstname in node with id [node-to-update:nid] needs updating with value \r\n[node-author:field-firstname]. To actually do so, replace this (informational) Rules Action with setting the appropriate value for the appropriate field ..." } }
    ]
  }
}

The actual action only displays a Drupal message (to show the values of the variables passed to it). Replace that action with the actual update of your cloned node.

Step 2: Update your existing Rule

Update your existing Rules Actions by performing the Rules Component (from step 1), whereas you pass these 2 parameters:

  • the node_to_update, which you can pass via the value (token) of the cloned node's nid.
  • the node_author, which you can pass via the value (token) of the cloned node's uid.
| improve this answer | |
  • 1
    Thank you @Pierre.Vriens! This works as well. I think I figured out why it was so difficult to obtain that value: I need to set a text field that can hold 3 values. The value of the firstname of course can have only 1 value. Another thing is that I had to put in a condition first: Entity is of bundle If you don't do this, you won't see the necessary fields obviously. – BassPlaya Feb 18 at 8:40
2

The problem was that I had to fetch the entity by property [cloned-node:author:field-firstname] inside the conditional and set the data value [cloned-node:field-student-name:0] to [firstname-fetched:0:field-firstname] I still don't understand the actual logic why [firstname-fetched:] has to be followed by [0:field-firstname] but that works. See screenshots. Hope this helps someone else out too.

Rules Events and Conditions Rules Actions part 1 Rules Actions part 2 Rules fetch entity by property part 1 Rules fetch entity by property part 2 Rules set the data value of the fetched entity

After @Pierre.Vriens helped out my component code is now:

    { "rules_update_the_cloned_course_with_values_for_the_student" : {
    "LABEL" : "Update the cloned Course with values for the Student",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "TAGS" : [ "cloned node", "component", "course", "update" ],
    "REQUIRES" : [ "rules_conditional", "rules" ],
    "USES VARIABLES" : {
      "node_to_update" : { "label" : "Node to be updated", "type" : "node" },
      "node_author" : { "label" : "Node author", "type" : "user" }
    },
    "ACTION SET" : [
      { "CONDITIONAL" : [
          {
            "IF" : { "entity_is_of_bundle" : {
                "entity" : [ "node-to-update" ],
                "type" : "node",
                "bundle" : { "value" : { "course" : "course" } }
              }
            },
            "DO" : [
              { "data_set" : {
                  "data" : [ "node-to-update:field-student-name:0" ],
                  "value" : [ "node-author:field-firstname" ]
                }
              },
              { "drupal_message" : { "message" : "Machine name of this Component was: \u0022rules_update_the_cloned_course_with_values_for_the_student\u0022" } },
              { "data_set" : { "data" : [ "node-to-update:field-status" ], "value" : "359" } }
            ]
          },
          { "ELSE" : [
              { "drupal_message" : {
                  "message" : "The field \u0022Student name\u0022 could not be set with the value of the Student\u0027s first name.\u003Cbr \/\u003E\r\nMachine name of this Component was: \u0022rules_update_the_cloned_course_with_values_for_the_student\u0022",
                  "type" : "warning"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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