Answers.Body: <p>I think you'll want to add a small extension that does this. So, you could add a custom field for this unique ID to memberships. Then you can set a <a href="https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postCommit/" rel="nofollow noreferrer">hook_civicrm_postCommit</a> for when a new membership is created and then use the API to check for the highest unique ID for that letter and set the new unique ID accordingly.</p>
  <p>Alternatively, you could possibly add this as a custom CiviRules action.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-04T10:06:46.030Z
Answers.Text: Thank you for your suggestions. May I understand how can I make use of civirules to help me create it?
Answers.UserDisplayName: Cas
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-04T14:21:40.663Z
Answers.Text: Here is the documentation on adding a custom CiviRules action:
  https://docs.civicrm.org/civirules/en/latest/create-your-own-action/
Answers.UserDisplayName: Lars SG
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-03T15:31:46.350Z
Answers.LastActivityDate: 2023-07-03T15:31:46.350Z
Answers.UserDisplayName: Lars SG
Body: <p>One of the requirements for a project was for the system to generate a unique ID for each of the members coming in. The logic of the unique ID is slightly complex. The unique ID will take the first alphabet of the surname and increment the number after the alphabet. Example John Tan, membership number will be T001 (Tan is his surname). Another example Ryan Tay, membership number will be T002 (Tay is his surname). If name if Tristan Ram, membership number will be R001 (Ram is his surname).</p>
  <p>Just wondering whether is this possible? And how can I create such custom logic in CiviCrm?</p>
  
Tags: <custom-fields><fields><custom>
Title: Custom logic for fields
ThreadText: # Custom logic for fields
  
  (Asked by: username_0 on 2023-07-03)
  
  One of the requirements for a project was for the system to generate a unique ID for each of the members coming in. The logic of the unique ID is slightly complex. The unique ID will take the first alphabet of the surname and increment the number after the alphabet. Example John Tan, membership number will be T001 (Tan is his surname). Another example Ryan Tay, membership number will be T002 (Tay is his surname). If name if Tristan Ram, membership number will be R001 (Ram is his surname).
  
  Just wondering whether is this possible? And how can I create such custom logic in CiviCrm?
  
  **Tags:** custom-fields, fields, custom
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-07-03. Score: 1
  
  I think you'll want to add a small extension that does this. So, you could add a custom field for this unique ID to memberships. Then you can set a [hook\_civicrm\_postCommit](https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postCommit/) for when a new membership is created and then use the API to check for the highest unique ID for that letter and set the new unique ID accordingly.
  
  Alternatively, you could possibly add this as a custom CiviRules action.
  
  > **Comments:**
  > **username_0**: Thank you for your suggestions. May I understand how can I make use of civirules to help me create it?  
  > **username_1**: Here is the documentation on adding a custom CiviRules action: https://docs.civicrm.org/civirules/en/latest/create-your-own-action/  
  
  ---
  
  