I observed that when using a Replicate action in Rules, we don't have access to the new replicated node fields, so we can't "set data values" for them.

We can only set data values for all the nodes of that content type, including the original one.

Is it something that I've missed or it's really not possible?

Can this option be added?

It will be very usefully, especially for the situations where you have, for example, a template node and you want to use Rules to replicate it and set data values only for the new one.

Comments

btopro’s picture

sounds like good functionality but i dont use rules personally so would accept patches

liberatr’s picture

StatusFileSize
new780 bytes

I have created a patch that allows you to do this. Actually pretty simple once you read the documentation.

Rules support improved!

Right now this just works for nodes, but with a tiny bit of work could be added to Users, Field Collections, etc I'm sure.

liberatr’s picture

Status: Active » Needs review
btopro’s picture

Simple enough, clean too. Can we get some verifieds that this works as I don't use Rules and didn't add the Rules integration to replicate_ui.

apmsooner’s picture

I verify patch in #2 is working flawlessly for me.

btopro’s picture

Status: Needs review » Fixed

sounds good to me, will roll a new release since this adds a lot of flexibility.

  • btopro committed 899003a on 7.x-1.x authored by liberatr
    Issue #2254055 by liberatr: In Rules, add the possibility to modify...

Status: Fixed » Closed (fixed)

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

cycas’s picture

I see that this patch is now in the dev version, but I can't get it working with Views Bulk Operations - should it work with that module?

I set up a view with a VBO field which replicates selected nodes, so far so good.

But when I set up a Rule that should trigger After Replication, with Entity has Field in the Conditions, my action 'set a data value' has no effect.

Am I missing something?

I'm trying to create a bunch of annual invoices that can be cloned and updated to the current year in one go.

btopro’s picture

I don't use Rules very frequently so can't be of help here unfortunately

apmsooner’s picture

@cycas, its been a little while since i used this however in your rule, i think you need to fetch the node after replicating it and do your actions on the fetched node. U can test it out by simply passing token variables in system message just to make sure before u try to set values

cycas’s picture

Thanks!

I tried fetching the node as my first action in Rules, and yes, I can now see the tokens appear in the right places in Rules Actions, but when I use VBO to replicate a node, my fields don't get updated.

I checked the logs, and my Rule 'after replication' just doesn't seem to be firing at all.

I discovered this by setting up a node creation rule for comparison : the 'after saving new content of type' rule works fine, it's just not triggering on 'after replication'. Ideally I'd like it to trigger on 'after replication' so it doesn't fire if someone creates a single node from scratch.

apmsooner’s picture

@cycas,

I think what i did was not use the 'after replication' event but rather set up all of your rules actions in a component and then use that component in vbo. Maybe your doing that already?

I believe i used this module https://www.drupal.org/project/rules_conditional to do everything within the actions with some logic like this:

1. replicate node
2. fetch entity by id > the new node
3. add conditional > entity is of bundle > entity fetched (do this to get field properties of new node)
4. Add action within conditional > set a data value
5. Save entity (not sure if needed but worth a try) > entity fetched

Again, i'd test with system messages using the tokens from new node just to make sure you are accessing the right object. Hope that helps...

apmsooner’s picture

@cycas, install rules_conditional module i posted above and import the following example below. Just add that component to your VBO actions. It works. You can then modify to your needs.

{ "rules_replicate_article" : {
    "LABEL" : "Replicate Article",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "replicate_ui", "rules", "rules_conditional" ],
    "USES VARIABLES" : { "node" : { "label" : "Node", "type" : "node" } },
    "ACTION SET" : [
      { "replicate_ui_replicate_node" : {
          "USING" : { "account" : [ "node" ] },
          "PROVIDE" : { "replica_node" : { "replica_node" : "Replica node" } }
        }
      },
      { "entity_fetch" : {
          "USING" : { "type" : "node", "id" : [ "replica-node:nid" ] },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
        }
      },
      { "CONDITIONAL" : [
          {
            "IF" : { "entity_is_of_bundle" : {
                "entity" : [ "entity-fetched" ],
                "type" : "node",
                "bundle" : { "value" : { "article" : "article" } }
              }
            },
            "DO" : [
              { "data_set" : {
                  "data" : [ "entity-fetched:title" ],
                  "value" : "A replica of: [node:title]"
                }
              }
            ]
          }
        ]
      }
    ]
  }
}
apmsooner’s picture

StatusFileSize
new1.16 KB

Heres a more user friendly .txt file

cycas’s picture

Ooh, thank you so much! I'll give that a go.

No, I wasn't using a component, although I do have Rules Conditional installed.

I wonder what 'after replication' is for then if it's not that. Oh well.