0

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

  • 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 – petednz - fuzion Dec 29 '18 at 21:42
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.

1

One way i could think of is to create a custom field on contacts, and use 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

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.

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.