Answers.Body: <p>We have made a participants view in Drupal that shows all event participants who have redeemed a code. We can then add them to a group for use in further searches in Civi. </p>
  
  <p>I don't know how you would do this with a smart group, but at least this might get you part of the way.</p>
  
  <p>We'll be doing a similar thing for memberships in due course, if that's possible.</p>
  
  <p>To do this you need:
  Drupal, Civicrm entity (ours is beta9), and turn on the sub module: civicrm_entity_actions as Pete mentions in the comments to the first answer here: <a href="https://civicrm.stackexchange.com/questions/12346/how-to-configure-views-vbo-action-to-disable-relationships">How to configure Views VBO action to disable relationships?</a>
  You also need Views Bulk Operations</p>
  
  <p>The participant view needs to have this relationship: CiviCRM Contributions: Contact Record ID</p>
  
  <p>The view also needs to have an exposed filter of the Participants fee level field. (NB, don't confuse this with the Events Fee level or the Contribution Amount label fields. They won't produce the same results).</p>
  
  <p>Then you can filter your view by keywords from your codes.</p>
  
  <p>Add the field, (CiviCRM Contact, with custom fields) Bulk operations: CiviCRM Contact. Note this will need a relationship to Civicrm Contact. Initially it won't give you the option to add a group, but after saving the field and then re-editing it you will see Add contact to group as an option.</p>
  
  <p>You will have had to previously made a suitable group in Civi. </p>
  
  <p>Et Voila! Now you can bulk add participants who've used your code to your group.</p>
  
  <p>I can send you an export of the view if that's helpful. Good luck!</p>
  
  <p>NB: it might be helpful to know that the Contributions: Amount label field will work fine for this purpose for online event bookings. But bookings taken through the admin interface may not contain the discount code in the Amount label field.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-02T15:57:54.047Z
Answers.LastActivityDate: 2017-12-02T15:57:54.047Z
Answers.UserDisplayName: Andyg8
Answers.Body: <p>Karin Gerritsen has created an update to the Extended Reports module to allow any discount codes to be exposed in a report, with various actions that can then be run on the search result, which is exactly what I wanted.  Previously the Extended reports only worked on discount codes for events, not for memberships.
  <a href="https://civicrm.stackexchange.com/questions/26829/can-extendedreports-report-on-cividiscount-usage">Can ExtendedReports report on CiviDiscount usage?</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-11T01:58:26.843Z
Answers.LastActivityDate: 2018-10-11T01:58:26.843Z
Answers.UserDisplayName: kathc
Answers.Body: <p>Andy's solution is related to what you ask, and Eli Lisseck's CiviDiscount report is too - but none of these will give you a custom search, which you need for a smart group.</p>
  
  <p>There's <a href="https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-search" rel="nofollow noreferrer">documentation on creating custom searches here</a>.  I think that if you write this extension, it'd be great to submit an answer to this question with a link to the Github!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-03T19:24:48.883Z
Answers.LastActivityDate: 2017-12-03T19:24:48.883Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>We've got CiviDiscount working to apply the appropriate discounts for memberships and events, but would like to be able to add all contacts that have used a discount to a report (for our sponsors) or smart group.  When I go to the CiviDiscount page, I can see the list of contacts who've redeemed each code, but would like to be able to search and act on that information.  So I guess my question is how can I add a Custom search for codes redeemed? </p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-12T11:24:18.797Z
Comments.Text: I note this question is a few years old, but I am facing the same problem and wondering if there have been any changes in CiviDiscount that would help, In our case we would like to offer a fixed discount for membership when one elects to go paperless with our publications. We would need a Smart Group that excludes those who have taken the discount to send to the mailing house.  I take it from the replies so far that this is not easily done.  Anything changed since then?  (One can hope.)
Comments.UserDisplayName: de Oldphart
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-08-13T12:44:18.747Z
Comments.Text: Not that I know of - the extended reports was enough for our use (we could search for any code and then add it to a group) so we didn't keep going. We're on Drupal with Webforms, so have moved to using that to replace a lot of our contributions and membership forms.
Comments.UserDisplayName: kathc
Tags: <cividiscount>
Title: How do I search for CiviDiscount code redeemed (to allow an action on those contacts)
ThreadText: # How do I search for CiviDiscount code redeemed (to allow an action on those contacts)
  
  (Asked by: username_0 on 2017-11-23)
  
  We've got CiviDiscount working to apply the appropriate discounts for memberships and events, but would like to be able to add all contacts that have used a discount to a report (for our sponsors) or smart group. When I go to the CiviDiscount page, I can see the list of contacts who've redeemed each code, but would like to be able to search and act on that information. So I guess my question is how can I add a Custom search for codes redeemed?
  
  **Tags:** cividiscount
  
  > **Comments:**
  > **username_1**: I note this question is a few years old, but I am facing the same problem and wondering if there have been any changes in CiviDiscount that would help, In our case we would like to offer a fixed discount for membership when one elects to go paperless with our publications. We would need a Smart Group that excludes those who have taken the discount to send to the mailing house.  I take it from the replies so far that this is not easily done.  Anything changed since then?  (One can hope.)  
  > **username_0**: Not that I know of - the extended reports was enough for our use (we could search for any code and then add it to a group) so we didn't keep going. We're on Drupal with Webforms, so have moved to using that to replace a lot of our contributions and membership forms.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2017-12-02. Score: 1
  
  We have made a participants view in Drupal that shows all event participants who have redeemed a code. We can then add them to a group for use in further searches in Civi.
  
  I don't know how you would do this with a smart group, but at least this might get you part of the way.
  
  We'll be doing a similar thing for memberships in due course, if that's possible.
  
  To do this you need:
  Drupal, Civicrm entity (ours is beta9), and turn on the sub module: civicrm\_entity\_actions as Pete mentions in the comments to the first answer here: [How to configure Views VBO action to disable relationships?](https://civicrm.stackexchange.com/questions/12346/how-to-configure-views-vbo-action-to-disable-relationships)
  You also need Views Bulk Operations
  
  The participant view needs to have this relationship: CiviCRM Contributions: Contact Record ID
  
  The view also needs to have an exposed filter of the Participants fee level field. (NB, don't confuse this with the Events Fee level or the Contribution Amount label fields. They won't produce the same results).
  
  Then you can filter your view by keywords from your codes.
  
  Add the field, (CiviCRM Contact, with custom fields) Bulk operations: CiviCRM Contact. Note this will need a relationship to Civicrm Contact. Initially it won't give you the option to add a group, but after saving the field and then re-editing it you will see Add contact to group as an option.
  
  You will have had to previously made a suitable group in Civi.
  
  Et Voila! Now you can bulk add participants who've used your code to your group.
  
  I can send you an export of the view if that's helpful. Good luck!
  
  NB: it might be helpful to know that the Contributions: Amount label field will work fine for this purpose for online event bookings. But bookings taken through the admin interface may not contain the discount code in the Amount label field.
  
  
  ---
  
  ### Answer by username_0 on 2018-10-11. Score: 1
  
  Karin Gerritsen has created an update to the Extended Reports module to allow any discount codes to be exposed in a report, with various actions that can then be run on the search result, which is exactly what I wanted. Previously the Extended reports only worked on discount codes for events, not for memberships.
  [Can ExtendedReports report on CiviDiscount usage?](https://civicrm.stackexchange.com/questions/26829/can-extendedreports-report-on-cividiscount-usage)
  
  
  ---
  
  ### Answer by username_3 on 2017-12-03. Score: 0
  
  Andy's solution is related to what you ask, and Eli Lisseck's CiviDiscount report is too - but none of these will give you a custom search, which you need for a smart group.
  
  There's [documentation on creating custom searches here](https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-search). I think that if you write this extension, it'd be great to submit an answer to this question with a link to the Github!
  
  
  ---
  
  