Answers.Body: <p>You'll need the module CiviCRM Entity installed. <a href="https://drupal.org/project/civicrm_entity" rel="nofollow noreferrer">https://drupal.org/project/civicrm_entity</a>
  You will also need the Webform Rules module <a href="https://drupal.org/project/webform_rules" rel="nofollow noreferrer">https://drupal.org/project/webform_rules</a></p>
  
  <p>What you could do is add a checkbox for each contact that can be deleted to the webform, could just be a regular Webform component. </p>
  
  <p>Then respond to the submission of that webform with a Rule. </p>
  
  <p>In the submission data, there will be a value for the checkbox you add. If it is checked, then load the contact by cid, it will also be there in the submission data. </p>
  
  <p>With CiviCRM Entity, CiviCRM entities like contact, become proper Drupal entity types, in this case civicrm_contact is the entity type. You can then use the regular "Delete an entity" Rules action. </p>
  
  <p>Before you delete the contact, you will have to load it first. There is a Rules action, "Fetch entity by id", use this, and pass it the contact id you get from the webform submission data. </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T16:19:27.510Z
Answers.LastActivityDate: 2018-05-08T16:19:27.510Z
Answers.UserDisplayName: jackrabbithanna
Answers.Body: <p>The other way would be to add the ability to a webform to set a contact to 'in trash' - assuming of course you really want them deleted rather than just have the relationship curtailed.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-08T19:53:41.863Z
Answers.LastActivityDate: 2018-05-08T19:53:41.863Z
Answers.UserDisplayName: petednz - fuzion
Body: <p>I am trying to fetch the contact entity in a rule which triggers when a specific tag is added to that contact. I seem to be able to load and fetch the Drupal user for the contact but not the actual contact entity itself. </p>
  
  <p>Is there a way for me to fetch the contact entity when a certain tag is added? </p>
  
  <p>I want to fetch the contact entity so I can then delete it, using entity delete action in rules.</p>
  
  <p>Ultimately I am using Webform for this which will add the tag which triggers the rule.</p>
  
  <p>I know this sounds a bit dangerous but I hope to put some safeguards in place to prevent anyone with access to the webform deleting any contacts!</p>
  
  <p><strong>EDIT to Clarify:</strong></p>
  
  <p>I am trying to build the ability to delete a contact in CiviCRM using a webform in Drupal.</p>
  
  <p>The way I wanted to do it, was that a CiviCRM contact with a Drupal user account logs into Drupal where they can see a list of all employees for the same organisation that they are employed by (I have done this part). I then want to give the logged in contact the ability to delete other employees of the organisation that they can see listed.</p>
  
  <p>I have already managed to give logged in users the ability to create new contacts for their organisation with an option to create a Drupal account for the new contact as well.</p>
  
  <p>I added the ability for logged in users to create new contacts, as well as a Drupal account, by following the very clear and helpful steps given in <a href="https://civicrm.stackexchange.com/questions/11768/how-can-i-create-a-drupal-user-when-someone-submits-a-civicrm-webform"><em>How can I create a Drupal user when someone submits a CiviCRM-Webform?</em></a></p>
  
  <p>This method above, involved adding a tag to a contact which then triggers the add Drupal account rule. I was thinking to use the same method of adding a tag to a contact to trigger the delete contact rule. however, I can't seem to fetch the contact as an entity within the rule in order to delete the entity.</p>
  
  <p>I am using Drupal 7.58 with CiviCRM 4.7.28.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-02T14:29:49.320Z
Comments.Text: Can you give a little more background? I assume you are using Drupal as CMS? What version of Drupal and what version of CiviCRM? What do you want to achieve functionally? It will help us to provide you with better answers.
Comments.UserDisplayName: ErikH - CiviCooP
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-02T15:26:24.970Z
Comments.Text: @ErikH - I have added in some background information to clarify the question.
Comments.UserDisplayName: Ben
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-02T19:36:05.757Z
Comments.Text: hi - as the author of that original blog i am interested to see how you get on. yes this sounds doable but am unclear if you are wanting to delete both the Contact, and the User if there is one connected to the Contact (which may require  2 separate actions in the right order)
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-03T11:31:35.363Z
Comments.Text: Hi Pete, thank you for your very helpful blog on this subject. If the contact has a Drupal account as well, then yes, I would want to delete the Drupal account and the Civi record. Not all contacts have a Drupal account as well though. I was thinking of using two seperate rules. One to delete the Drupal account and the other to delete the contact in Civi. I had got the rule for deleting the Drupal account working. It is just now to work out how to delete the contact in Civi...
Comments.UserDisplayName: Ben
Tags: <drupal><webform-civicrm><drupal-rules>
Title: In Rules Fetch Contact Entity from Tag Creation
ThreadText: # In Rules Fetch Contact Entity from Tag Creation
  
  (Asked by: username_0 on 2018-05-02)
  
  I am trying to fetch the contact entity in a rule which triggers when a specific tag is added to that contact. I seem to be able to load and fetch the Drupal user for the contact but not the actual contact entity itself.
  
  Is there a way for me to fetch the contact entity when a certain tag is added?
  
  I want to fetch the contact entity so I can then delete it, using entity delete action in rules.
  
  Ultimately I am using Webform for this which will add the tag which triggers the rule.
  
  I know this sounds a bit dangerous but I hope to put some safeguards in place to prevent anyone with access to the webform deleting any contacts!
  
  **EDIT to Clarify:**
  
  I am trying to build the ability to delete a contact in CiviCRM using a webform in Drupal.
  
  The way I wanted to do it, was that a CiviCRM contact with a Drupal user account logs into Drupal where they can see a list of all employees for the same organisation that they are employed by (I have done this part). I then want to give the logged in contact the ability to delete other employees of the organisation that they can see listed.
  
  I have already managed to give logged in users the ability to create new contacts for their organisation with an option to create a Drupal account for the new contact as well.
  
  I added the ability for logged in users to create new contacts, as well as a Drupal account, by following the very clear and helpful steps given in [*How can I create a Drupal user when someone submits a CiviCRM-Webform?*](https://civicrm.stackexchange.com/questions/11768/how-can-i-create-a-drupal-user-when-someone-submits-a-civicrm-webform)
  
  This method above, involved adding a tag to a contact which then triggers the add Drupal account rule. I was thinking to use the same method of adding a tag to a contact to trigger the delete contact rule. however, I can't seem to fetch the contact as an entity within the rule in order to delete the entity.
  
  I am using Drupal 7.58 with CiviCRM 4.7.28.
  
  **Tags:** drupal, webform-civicrm, drupal-rules
  
  > **Comments:**
  > **username_1**: Can you give a little more background? I assume you are using Drupal as CMS? What version of Drupal and what version of CiviCRM? What do you want to achieve functionally? It will help us to provide you with better answers.  
  > **username_0**: @username_1 - I have added in some background information to clarify the question.  
  > **username_2**: hi - as the author of that original blog i am interested to see how you get on. yes this sounds doable but am unclear if you are wanting to delete both the Contact, and the User if there is one connected to the Contact (which may require  2 separate actions in the right order)  
  > **username_0**: Hi Pete, thank you for your very helpful blog on this subject. If the contact has a Drupal account as well, then yes, I would want to delete the Drupal account and the Civi record. Not all contacts have a Drupal account as well though. I was thinking of using two seperate rules. One to delete the Drupal account and the other to delete the contact in Civi. I had got the rule for deleting the Drupal account working. It is just now to work out how to delete the contact in Civi...  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2018-05-08. Score: 0 | Accepted answer
  
  You'll need the module CiviCRM Entity installed. <https://drupal.org/project/civicrm_entity>
  You will also need the Webform Rules module <https://drupal.org/project/webform_rules>
  
  What you could do is add a checkbox for each contact that can be deleted to the webform, could just be a regular Webform component.
  
  Then respond to the submission of that webform with a Rule.
  
  In the submission data, there will be a value for the checkbox you add. If it is checked, then load the contact by cid, it will also be there in the submission data.
  
  With CiviCRM Entity, CiviCRM entities like contact, become proper Drupal entity types, in this case civicrm\_contact is the entity type. You can then use the regular "Delete an entity" Rules action.
  
  Before you delete the contact, you will have to load it first. There is a Rules action, "Fetch entity by id", use this, and pass it the contact id you get from the webform submission data.
  
  
  ---
  
  ### Answer by username_2 on 2018-05-08. Score: 0
  
  The other way would be to add the ability to a webform to set a contact to 'in trash' - assuming of course you really want them deleted rather than just have the relationship curtailed.
  
  
  ---
  
  