Answers.Body: <p>I also used ContactID to hold membership ID for the same reason that a unique value is allocated by CiviCRM. There doesn't seem to me any standard way to have an autoincrement field in CiviCRM without doing some coding. You also have to think whether the membership ID should be in the membership record rather than the contact record, though because I had some historical data, I decided against this. To get the historical data in I created records for all the membership numbers up to the last one previously used, but tagged all that hadn't been used so that I could delete them all later. I think imported all these records and they were automatically allocated the matching contact id (fortunately I didn't have a membership 1 which was already allocated to the admin account. I then deleted the contacts for the numbers that hadn't been previously used. New contacts were autoincremented from the last one I had used. You might be able to do a trick to get your numbers starting 2019 etc, but that would mean creating a hell of a lot of records and then deleting them, so not sure its a sensible option, but you could try (maybe with just a 19 prefix, so you would be OK for the next 80 years).</p>
  
  <p>I don't think that CiviRules has anything built in that will create an autoincrement field. Indeed I can't see something available off the shelf to set a custom field. I think you would need to write some code.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-29T11:08:32.530Z
Answers.LastActivityDate: 2018-12-29T11:08:32.530Z
Answers.UserDisplayName: Mick Kahn
Answers.Body: <p>One way i could think of is to create a custom field on contacts, and use <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/" rel="nofollow noreferrer">hook_civicrm_post</a> hook using following conditions:</p>
  
  <ul>
  <li>$op = create </li>
  <li>$objectName = contact</li>
  </ul>
  
  <p>You will get contact Id in $objectId variable, then you can use CiviCRM API to update custom field value based on whatever pattern+contactID you desire.</p>
  
  <p>Thanks</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-29T00:11:20.263Z
Answers.LastActivityDate: 2019-01-29T00:11:20.263Z
Answers.UserDisplayName: Hassan Farooq
Answers.Body: <p>I would check out the CiviCRM docs to create a custom field: <a href="https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/" rel="nofollow noreferrer">https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/</a></p>
  
  <p>We used the Contact ID for our membership ID's because they are automatically a unique ID. For something like 2019-### you would probably have to manual enter each or write something to do that. You could maybe use CiviRules to help.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-29T00:09:32.197Z
Answers.LastActivityDate: 2018-12-29T00:09:32.197Z
Answers.UserDisplayName: Scott Pulver
Body: <p>Newbie question. 
  I'm looking for a way to add a custom field to each contact that will be a unique membership ID but based on a pattern, eg. 2019-### etc.
  I'm using Civi with Drupal 7</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-12-29T21:42:22.187Z
Comments.Text: Given that there is already a unique Custom Id for both the Contact and any Membership they purchase - in what context do you need your 2019-###. If you only need it for a display/list then you could just create this in a View by grabbing the year of payment, and the membership id (or contact id) and concatenating them in the display
Comments.UserDisplayName: petednz - fuzion
Tags: <civimember>
Title: Contact membership ID based on a pattern
ThreadText: # Contact membership ID based on a pattern
  
  (Asked by: username_0 on 2018-12-27)
  
  Newbie question.
  I'm looking for a way to add a custom field to each contact that will be a unique membership ID but based on a pattern, eg. 2019-### etc.
  I'm using Civi with Drupal 7
  
  **Tags:** civimember
  
  > **Comments:**
  > **username_1**: Given that there is already a unique Custom Id for both the Contact and any Membership they purchase - in what context do you need your 2019-###. If you only need it for a display/list then you could just create this in a View by grabbing the year of payment, and the membership id (or contact id) and concatenating them in the display  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2018-12-29. Score: 1
  
  I also used ContactID to hold membership ID for the same reason that a unique value is allocated by CiviCRM. There doesn't seem to me any standard way to have an autoincrement field in CiviCRM without doing some coding. You also have to think whether the membership ID should be in the membership record rather than the contact record, though because I had some historical data, I decided against this. To get the historical data in I created records for all the membership numbers up to the last one previously used, but tagged all that hadn't been used so that I could delete them all later. I think imported all these records and they were automatically allocated the matching contact id (fortunately I didn't have a membership 1 which was already allocated to the admin account. I then deleted the contacts for the numbers that hadn't been previously used. New contacts were autoincremented from the last one I had used. You might be able to do a trick to get your numbers starting 2019 etc, but that would mean creating a hell of a lot of records and then deleting them, so not sure its a sensible option, but you could try (maybe with just a 19 prefix, so you would be OK for the next 80 years).
  
  I don't think that CiviRules has anything built in that will create an autoincrement field. Indeed I can't see something available off the shelf to set a custom field. I think you would need to write some code.
  
  
  ---
  
  ### Answer by username_3 on 2019-01-29. Score: 1
  
  One way i could think of is to create a custom field on contacts, and use [hook\_civicrm\_post](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_post/) hook using following conditions:
  
  * $op = create
  * $objectName = contact
  
  You will get contact Id in $objectId variable, then you can use CiviCRM API to update custom field value based on whatever pattern+contactID you desire.
  
  Thanks
  
  
  ---
  
  ### Answer by username_4 on 2018-12-29. Score: 0
  
  I would check out the CiviCRM docs to create a custom field: <https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/>
  
  We used the Contact ID for our membership ID's because they are automatically a unique ID. For something like 2019-### you would probably have to manual enter each or write something to do that. You could maybe use CiviRules to help.
  
  
  ---
  
  