0

I have two content types A and B and I have two rules. I am trying to add the text put in the A text field of content type A into the B text field of content type B.

On rule two I am using the set data value but it is not working. Have I missed anything or have I setup my rule incorrectly? If anybody can point out where I went wrong it would be much appreciated.

Rule 1 creates a node from content type B when a node is created with content type A.

Export of Rule 1:

{ "rules_ref" : {
    "LABEL" : "Ref",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--a" : { "bundle" : "a" } },
    "DO" : [
      { "entity_create" : {
         "USING" : {
            "type" : "node",
             "param_type" : "b",
             "param_title" : [ "node:type" ],
             "param_author" : [ "node:author" ]
          },
         "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
       }
     }
    ]
} }

Rule2 takes the value from A text field in the A content type and adds it to the B text field in the B content Type.

Export of Rule 2:

{ "rules_ref2" : {
  "LABEL" : "Ref2",
  "PLUGIN" : "reaction rule",
  "OWNER" : "rules",
  "REQUIRES" : [ "rules" ],
  "ON" : { "node_insert--b" : { "bundle" : "b" } },
  "IF" : [
    { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_a_text" } },
    { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_b_text" } }
    ],
  "DO" : [
     { "data_set" : { "data" : [ "node:field-b-text" ], "value" : "[node:field-a-text]" } }
   ]
} }
1

Here is example

  • Content type Article: field_product - Product reference
  • Content type Basic page: field_product2 - Product reference

Article creation triggers next actions:

{ "rules_on_article_create" : {
    "LABEL" : "On Article create",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_insert--article" : { "bundle" : "article" } },
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "node",
            "param_type" : "page",
            "param_title" : [ "node:title" ],
            "param_author" : [ "node:author" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "data_set" : {
          "data" : [ "entity-created:field-product2" ],
          "value" : [ "node:field-product" ]
        }
      }
    ]
  }
}

I think you r trying to operate with non existing object. When you r creating node of type B there is no link to any another node in rules.

  • Thank you so much Ar7max I originally was on this path but for some reason decided to split the rules but i guess that was where the mistake was made. – Roadkill Aug 18 '15 at 13:52
  • I must apologise cuz said incorrect decision due to bad understanding of english language. I tried to say that when you r working with some events that invoked on some node creation you can access only that node object (fileds of that node). When u r working with node2 event there is no other node for program, only node2. In this way u should create entity in first rule and make your work with em in the same rule. It called scope in programming.That's it, I think. – ar7max Aug 18 '15 at 13:58
  • No you are absolutely correct and the advice that you gave me was the solution I was looking for thank you. – Roadkill Aug 25 '15 at 8:53
  • @user14502, you are welcome, glad it works for you! – ar7max Aug 25 '15 at 10:12

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.