I'm trying to fetch contact entity in rules using "Fetch entity by property" action. I've selected my contact entity type and "Email" property but it's not loading my contact.
Is this supposed to work like that?
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | rules_fetch_contact_entity_by_email-1933056-6.patch | 2.34 KB | philipz |
| #2 | rules_fetch_contact_entity_by_email-1933056-2.patch | 1.58 KB | philipz |
| #1 | rules_fetch_contact_entity_by_email-1933056.patch | 1.61 KB | philipz |
Comments
Comment #1
philipz commentedWell I don't know if this was needed but here's my patch adding rule to fetch redhen contact entity by email.
It is based on redhen_engagement rules and core rules fetch entity by property rule.
Comment #2
philipz commentedSome corrections.
Comment #3
seanberto commentedI'd like to review this patch. It would be helpful if you could had a moment to shoot us a quick Rules export that leverages this code.
Comment #4
philipz commentedGreat to hear :)
My use case is pretty complicated. I'm using a panels variant to fire a rule that takes a parameter from URL (email) and looks for a contact matching the e-mail. Then it assigns the Entityform registration based on first parameter from URL to the contact if it matches.
I would have to come up with a simpler example for Rules export. I'll try to do that soon.
Comment #5
parampadam commentedIn my use case, i import mails via mailhandler, and connect the imported Mails with my redhen contacts.
If there is no contact i'd like to create one.
The patch in #2 is working, but without an existing Mail address, there is an error message:
Warning: array_shift() expects parameter 1 to be array, boolean given in redhen_contact_rules_action_fetch_by_mail()
My rule is:
{ "rules_mail_import" : {
"LABEL" : "mail import",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "redhen_contact", "rules_conditional", "feeds" ],
"ON" : { "feeds_import_mail_importer" : [] },
"IF" : [
{ "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "mails" : "mails" } } } }
],
"DO" : [
{ "fetch_contact_by_mail" : {
"USING" : { "mail" : [ "node:field-mail-from-address" ] },
"PROVIDE" : { "fetched_contact" : { "fetched_contact" : "Fetched contact" } }
}
},
{ "CONDITIONAL" : [
{
"IF" : { "entity_is_of_bundle" : {
"entity" : [ "fetched-contact" ],
"type" : "redhen_contact",
"bundle" : { "value" : { "kontakte" : "kontakte" } }
}
},
"DO" : [
{ "data_set" : { "data" : [ "node:field-contact-ref" ], "value" : [ "fetched-contact" ] } },
{ "entity_save" : { "data" : [ "node" ], "immediate" : 1 } }
]
}
]
}
]
}
}
thanks for help
Comment #6
philipz commentedIt's been a while and I've changed patch #2 since then. Here's new one against latest dev. This one should not cause warnings for you and I've added a condition to check if contact exists by email too.
Comment #7
parampadam commentedYour patch works great, thank you
Comment #8
philipz commentedGreat to hear! I still hope this goes into Redhen Contact so...
Comment #11
gcbThanks @philipz!