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.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | replicate_rule.txt | 1.16 KB | apmsooner |
| #2 | replicate_ui-rules_modify-2254055-2.patch | 780 bytes | liberatr |
Comments
Comment #1
btopro commentedsounds like good functionality but i dont use rules personally so would accept patches
Comment #2
liberatrI 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.
Comment #3
liberatrComment #4
btopro commentedSimple 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.
Comment #5
apmsooner commentedI verify patch in #2 is working flawlessly for me.
Comment #6
btopro commentedsounds good to me, will roll a new release since this adds a lot of flexibility.
Comment #9
cycas commentedI 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.
Comment #10
btopro commentedI don't use Rules very frequently so can't be of help here unfortunately
Comment #11
apmsooner commented@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
Comment #12
cycas commentedThanks!
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.
Comment #13
apmsooner commented@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...
Comment #14
apmsooner commented@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.
Comment #15
apmsooner commentedHeres a more user friendly .txt file
Comment #16
cycas commentedOoh, 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.