Hi guys.

I'm trying to create a rule triggered after a node is created and with an action to create a comment on this node.

The comments include a couple additional fields (text, file, etc) , and i need to set some of these with data from the node.

But the data selectors to specify the data to be set does not includes the entity created additional fields, it just lists standard comment fields as author, subject , body, etc.

Similar problem when trying to add an item to a list of files on the comment. There is no data selector available for it.

Is this supposed to work? I'm doing something wrong?

Thanks a lot.

CommentFileSizeAuthor
#7 selectors_for_comment_bodypng.png30.2 KBchi

Comments

itangalo’s picture

To use the fields, you must add conditions that verifies that the fields exist on the enitities you're handling. Some more information about this can be found in this screencast: http://nodeone.se/node/987

I hope it may be of help.

//Johan Falk, NodeOne, Sweden
PS: I'm not maintaining the Rules module, just helping with support questions. You are welcome to ask more questions at http://groups.drupal.org/rules

itangalo’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

chi’s picture

Version: 7.x-2.0-rc1 » 7.x-2.x-dev
Status: Closed (fixed) » Active

Have the same problem. I am trying to set comment body from with data from node (field_status is a single texfield).

{ "rules_test" : {
    "LABEL" : "Test",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_status" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "comment",
            "param_subject" : "Hello word!",
            "param_node" : [ "node" ],
            "param_author" : [ "node:author" ],
            "param_comment_body" : [ "node:field-status" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      }
    ]
  }
}

When I save the rule above I got this error message:
Integrity check for the imported configuratoin failed. Error message: The data type of the configured argument does not match the parameter's param_comment_body requirement..

itangalo’s picture

Priority: Major » Normal
Status: Active » Fixed

I think the comment body has two parts – the text format and the actual text. Try inserting the text in the 'value' part of the body, and I think this should work.

chi’s picture

Status: Fixed » Active

I don't got hang of this.

Here my current rule:

{ "rules_test" : {
    "LABEL" : "Test",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_status" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "comment",
            "param_subject" : [ "node:field-status" ],
            "param_node" : [ "node" ],
            "param_author" : [ "node:author" ],
            "param_comment_body" : [ "node:body" ]
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      }
    ]
  }
}

Field status is a simple text list. I was able to set comment subject from field_status but not comment body. Because I could not find suitable token in data selectors section (see screenshot). "node:body" is only thing that I was able to set for comment body.

chi’s picture

StatusFileSize
new30.2 KB

screen

itangalo’s picture

Hm, you should get more data avilable if you drill into node:body:. (Note the trailing colon!) This assumes that the body is *formatted* text, not plain text.

Basically, what you got is this:

A formatted text has body:format and body:value.
A plain text has only text.

If you try to set a plain text value, you must input a matching data – such as body:value.

I recommend using the dropdown on the right side of the data selector, rather than the list of data selectors below the widget. (Actually, that list should probably be removed.) If you use the data selector to drill down into the available data, you will get more useful lists of data.

(Note that if your status field is *not* a plain text field – for example an integer field or a list of text – Rules won't accept text data as input for it. There are ways to work around this, too.)

itangalo’s picture

Here's a screencast explaining a bit more about the data selector: http://dev.nodeone.se/en/data-types-and-data-selection

chi’s picture

Status: Active » Fixed

Thanks! I've seen all your screencasts about rules module. As far as I understood it param_comment_body doesn't assume any data types except 'formatted text'. It isn't possible to set directly value or format of the comment body through UI.

Now, I've done it with data_set action. Of course this kind of tricky if you can do it without data_set action please share your rule.

{ "rules_test" : {
    "LABEL" : "Comment bot",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules" ],
    "ON" : [ "node_update" ],
    "IF" : [
      { "entity_has_field" : { "entity" : [ "node" ], "field" : "field_status" } }
    ],
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "comment",
            "param_subject" : "zzz",
            "param_node" : [ "node" ],
            "param_author" : [ "node:author" ],
            "param_comment_body" : { "value" : {
                "value" : "This text will be replaced in the next action.",
                "format" : "filtered_html"
              }
            }
          },
          "PROVIDE" : { "entity_created" : { "new_comment" : "New comment" } }
        }
      },
      { "data_set" : {
          "data" : [ "new-comment:comment-body:value" ],
          "value" : [ "node:field-status" ]
        }
      }
   ]
  }
} 
itangalo’s picture

Great!
I would have used the 'set data value' action myself, and don't really know how to do it in another way.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Energyblazar’s picture

Status: Closed (fixed) » Active

hello i am facing a problem which is very similar.

I have added user reference field in the comment form of a group (group created via organic group).

How do i access this extra field it in rules ?

mitchell’s picture

Component: Rules Engine » Rules Core

Updated component.

tr’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

This was asked and answered and closed by #12.

It was reopened in #13 for a related issue, but no details were provided (unlike the original issue, where lots of details and exports of rules were posted).

After almost 6 years with no reply, I'm going to assume #13 is no longer relevant - regardless, there is not enough information to address #13, and you should open a new issue with details if this is still a problem.