2

I am trying to add the current user logged in to the Drupal 7 site to a CiviCRM group when they add content. For example we have a business directory and the signed in user can submit their listing. I want the user who submits the listing to be added a CiviCRM group called business directory which can then be used to email them in the future.

I tried using the contact reference field but this allows me to select the user. We want it to automatically select the signed in user.

Further, I am trying to get the rule to add the user to the group.

Has anyone achieved this with Drupal 7 & CiviCRM 4.7X.

Thanks.

3

You can use rules module where you set condition upon node submit to perform to add user to CiviCRM group.

Module: Rules/ CiviRules

  • Hi Pradeep. I have tried that but I can't seem to get the rules to work. It does not fetch the right details to add in the data selector. Any ideas? – Sohal Khatwani May 9 '18 at 12:33
  • What details are you looking for?? – Pradeep Nayak May 9 '18 at 12:50
  • Also - you may need to have civicrm_entity installed as well. – Jon G - Megaphone Tech May 9 '18 at 16:05
  • Thanks Guys. @PradeepNayak - I am having trouble with the data selector to add the Contact to the CiviCRM Group. I will edit the question and link an image there. I have installed the civicrm_entity module. – Sohal Khatwani May 9 '18 at 23:28
  • For anyone looking for the answer I have added this below. – Sohal Khatwani Sep 11 '18 at 11:44
1

On a node update (You can change it to node create) it captures the email address from the node i.e. directory and creates a new Drupal user and CiviCRM contact and assigns that contact to the group.

{ "rules_add_new_user_to_civicrm_group_working" : {
    "LABEL" : "Add New User to CiviCRM Group - Working with New User",
    "PLUGIN" : "reaction rule",
    "ACTIVE" : false,
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "civicrm", "civicrm_entity" ],
    "ON" : { "node_update--directory" : { "bundle" : "directory" } },
    "DO" : [
      { "entity_create" : {
          "USING" : {
            "type" : "user",
            "param_name" : "[node:title]",
            "param_mail" : "[node:field-directory-email]"
          },
          "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
        }
      },
      { "entity_save" : { "data" : [ "entity-created" ], "immediate" : "1" } },
      { "civicrm_entity_action_load_create_contact" : {
          "USING" : { "user" : [ "entity-created" ], "email" : [ "" ] },
          "PROVIDE" : { "civicrm_contact" : { "civicrm_contact" : "Created or Loaded CiviCRM Contact" } }
        }
      },
      { "civicrm_entity_query" : {
          "USING" : {
            "type" : "civicrm_contact",
            "property" : "id",
            "value" : [ "civicrm-contact:id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched CiviCRM entity list" } }
        }
      },
      { "civicrm_entity_rules_action_assign_contact_to_group" : {
          "contact" : [ "entity-fetched:0:contact-id-contact" ],
          "group_id" : { "value" : { "2" : "2" } }
        }
      }
    ]
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.