Answers.Body: <p>Unfortunately Drupal rules module is not triggered on CiviCRM membership CRUD function and CiviRules does but doesn't provide option to perform any CMS changes like creating OG groups in your case. I would recommend to create an extension or drupal module and use CiviCRM post <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/" rel="nofollow noreferrer">hook</a> to create OG group.
  eg:</p>
  <pre><code>function extensions_civicrm_post($op, $objectName, $objectId, &amp;$objectRef) {
    if ($objectName == 'Membership' &amp;&amp; $op == 'create') {
      try {
        $orgName = civicrm_api3('Contact', 'getvalue', [
          'return' =&gt; &quot;organization_name&quot;,
          'id' =&gt; 1,
          'contact_type' =&gt; &quot;Organization&quot;,
        ]);
      }
      catch (CiviCRM_API3_Exception $e) {
        // Not a organization contact
        return;
      }
      // get the user id who will controll this group either Employee of relationship?
      $userId = 1;
  
      //create OG
      $node = new stdClass();
      $node-&gt;type = &quot;og_node&quot;; // use the machine name of OG group node type
      node_object_prepare($node);
      $node-&gt;title = $orgName;
      $node-&gt;language = LANGUAGE_NONE;
      $node-&gt;uid = $userId;
      $node-&gt;group_group[LANGUAGE_NONE][0]['value'] = TRUE;
      node_save($node);
  
      $roles = array_flip(og_roles('node', 'og_node', $node-&gt;nid));
      og_role_grant('node', $node-&gt;nid, $user-&gt;uid, $roles[OG_ADMINISTRATOR_ROLE]);
      $values = [
        'entity_type' =&gt; 'user',
        'entity' =&gt; $userId,
      ];
      og_group('node', $node-&gt;nid, $values);
    }
  }
  </code></pre>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-24T10:32:23.037Z
Answers.LastActivityDate: 2018-07-24T10:32:23.037Z
Answers.LastEditDate: 2020-06-17T09:00:50.810Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>trying to implement the following workflow - New Organisation Membership approval in CiviMember creates OG in Drupal called after Org, with Org drupal account as OG admin.
   I'm looking at maybe using Rules, but I'm a bit new to the module, any tips appreciated.</p>
  
  <p>CiviCRM 5.3.0 Drupal 7.59</p>
  
Tags: <civimember><drupal-rules>
Title: Drupal OG creation on Membership
ThreadText: # Drupal OG creation on Membership
  
  (Asked by: username_0 on 2018-07-17)
  
  trying to implement the following workflow - New Organisation Membership approval in CiviMember creates OG in Drupal called after Org, with Org drupal account as OG admin.
  I'm looking at maybe using Rules, but I'm a bit new to the module, any tips appreciated.
  
  CiviCRM 5.3.0 Drupal 7.59
  
  **Tags:** civimember, drupal-rules
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-07-24. Score: 1 | Accepted answer
  
  Unfortunately Drupal rules module is not triggered on CiviCRM membership CRUD function and CiviRules does but doesn't provide option to perform any CMS changes like creating OG groups in your case. I would recommend to create an extension or drupal module and use CiviCRM post [hook](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/) to create OG group.
  eg:
  
  ```
  function extensions_civicrm_post($op, $objectName, $objectId, &$objectRef) {
    if ($objectName == 'Membership' && $op == 'create') {
      try {
        $orgName = civicrm_api3('Contact', 'getvalue', [
          'return' => "organization_name",
          'id' => 1,
          'contact_type' => "Organization",
        ]);
      }
      catch (CiviCRM_API3_Exception $e) {
        // Not a organization contact
        return;
      }
      // get the user id who will controll this group either Employee of relationship?
      $userId = 1;
  
      //create OG
      $node = new stdClass();
      $node->type = "og_node"; // use the machine name of OG group node type
      node_object_prepare($node);
      $node->title = $orgName;
      $node->language = LANGUAGE_NONE;
      $node->uid = $userId;
      $node->group_group[LANGUAGE_NONE][0]['value'] = TRUE;
      node_save($node);
  
      $roles = array_flip(og_roles('node', 'og_node', $node->nid));
      og_role_grant('node', $node->nid, $user->uid, $roles[OG_ADMINISTRATOR_ROLE]);
      $values = [
        'entity_type' => 'user',
        'entity' => $userId,
      ];
      og_group('node', $node->nid, $values);
    }
  }
  
  ```
  
  HTH
  
  username_1
  
  
  ---
  
  