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?

Comments

philipz’s picture

Status: Active » Needs review
StatusFileSize
new1.61 KB

Well 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.

philipz’s picture

Some corrections.

seanberto’s picture

I'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.

philipz’s picture

Great 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.

parampadam’s picture

In 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

philipz’s picture

It'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.

parampadam’s picture

Status: Needs review » Closed (fixed)

Your patch works great, thank you

philipz’s picture

Status: Closed (fixed) » Needs review

Great to hear! I still hope this goes into Redhen Contact so...

  • Commit b4f8b9c on 7.x-1.x, redhen-donation authored by philipz, committed by levelos:
    #1933056 by philipz: Add Rules action and condition for managing...

  • Commit b4f8b9c on 7.x-1.x, redhen-donation, relation-roles authored by philipz, committed by levelos:
    #1933056 by philipz: Add Rules action and condition for managing...
gcb’s picture

Issue summary: View changes
Status: Needs review » Closed (fixed)

Thanks @philipz!