2

I'm trying to create a rule that fires upon saving a node with a few conditions. The rule takes the current author, and sets it in a field called "field_original_author" and after that changes the value of the current author information to a particular author.

It does the first bit but not the second. Even if I only use the second part, it still doesn't change the author information into the other author that I specified.

What gives?

1

I can't remember exactly, but you can create an action "Fetch entity by ID". Add user as the entity type, and create another action "Set a data value" with selected data [node:author]

  • Thank you Collins, that worked. But I don't understand why my method didn't work. In my method I used: Parameter: Data to compare: [node:field-native-language], Data value: 58. And in your method: Parameter: Data to compare: [creating-author-fetched:field-native-language], Data value: 58 – BassPlaya Apr 28 '14 at 7:40
  • It looks like its because you needed to create that reference with the fetched author field to display the correct value. Anyway, glad you got it working! :) – Collins Apr 28 '14 at 8:03
  • Oh... I see it now. The 'native language' field exists on both the content type AND on the author entity as a field. I wrongly selected the type. Sorry for bothering everyone here. But I do want to point out that this works WITHOUT fetch entity by ID. However I do appreciate your reply, Collins. Have a good one. – BassPlaya Apr 28 '14 at 8:11
  • 1
    So I now use: Parameter: Data to compare: [node:author:field-native-language], Data value: 58 instead of [creating-author-fetched:field-native-language], Data value: 58. But basically the results are the same. – BassPlaya Apr 28 '14 at 8:13
0

Have a look at this custom rule, which should answer the "...after that changes the value of the current author information to a particular author" part of your question:

{ "rules_optionally_change_node_author" : {
    "LABEL" : "Optionally hide change author",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules" ],
    "ON" : { "node_presave" : [] },
    "IF" : [
      { "node_is_of_type" : {
          "node" : [ "node" ],
          "type" : { "value" : {
              "article" : "article"
            }
          }
        }
      },
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_optionlist" } },
      { "data_is" : { "data" : [ "node:field-optionlist" ], "value" : "C" } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : { "type" : "user", "id" : "68" },
          "PROVIDE" : { "entity_fetched" : { "user_fetched" : "Fetched user" } }
        }
      },
      { "data_set" : { "data" : [ "node:author" ], "value" : [ "user-fetched" ] } }
    ]
  }
}

Some more details about this rule:

  • The rule checks that the content type is "Article" (adapt to fit your needs, or just omit it if you want this logic to be applied for any content type).
  • I added 2 extra Rules Conditions to verify that the field with machine name "field_optionslist" has a value of "C" (adapt to fit your needs).
  • In the Rules Action, it fetches the user with uid=68 (replace 68 in it by the uid that matches your particular author).

PS: I'm assuming this question is about D7.

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.