Answers.Body: <p>CiviCRM keeps track of membership changes in civicrm_membership_log table for all changes to membership attributes like start date, end date, status. But it will pretty difficult for you to guess if the membership is actually being renewed or updated unless you perform some more checks with different log entries from civicrm_membership_log table. </p>
  
  <p>The other and most easiest/convenient way to know renewal or status change is through Activities. CiviCRM create different activities for membership when a membership is added, renewed and status/type is changed etc(see in attached image list of Activity types for membership). So it will be easy to use post or pre hook on Activity to guess the context. </p>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-10T12:46:08.103Z
Answers.Text: Thank you so much. Before I post this question, I decided to use your second method. But, I worried about the data integrity because I'm not sure that pre and post hook perform in same db transaction.
Answers.UserDisplayName: pnbps
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-10T12:49:06.240Z
Answers.Text: Depends on the requirement.
Answers.UserDisplayName: Pradeep Nayak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-10T12:21:41.953Z
Answers.LastActivityDate: 2018-10-10T12:21:41.953Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>CiviCRM keeps log tables that document changes to core tables like <code>civicrm_membership</code>. They're all prefixed <code>log_</code>, so in this case you could look for the newest row in <code>log_civicrm_membership</code> for the relevant <code>contact_id</code> and/or <code>id</code> (<code>id</code> being the membership ID from the core table).</p>
  
  <p>That might contain enough data to help you distinguish between the two cases you describe.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-10T12:06:25.757Z
Answers.LastActivityDate: 2018-10-10T12:06:25.757Z
Answers.UserDisplayName: John Twyman
Body: <p>I'm going to write a hook to distinguish a saved membership record, how do I know the last action of saved membership record is edit or renewal?</p>
  
Tags: <civimember><hooks>
Title: Is there any information that tells the last action of membership record (edit or renewal)?
ThreadText: # Is there any information that tells the last action of membership record (edit or renewal)?
  
  (Asked by: username_0 on 2018-10-10)
  
  I'm going to write a hook to distinguish a saved membership record, how do I know the last action of saved membership record is edit or renewal?
  
  **Tags:** civimember, hooks
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-10-10. Score: 2 | Accepted answer
  
  CiviCRM keeps track of membership changes in civicrm\_membership\_log table for all changes to membership attributes like start date, end date, status. But it will pretty difficult for you to guess if the membership is actually being renewed or updated unless you perform some more checks with different log entries from civicrm\_membership\_log table.
  
  The other and most easiest/convenient way to know renewal or status change is through Activities. CiviCRM create different activities for membership when a membership is added, renewed and status/type is changed etc(see in attached image list of Activity types for membership). So it will be easy to use post or pre hook on Activity to guess the context.
  
  HTH
  
  Pradeep
  
  > **Comments:**
  > **username_0**: Thank you so much. Before I post this question, I decided to use your second method. But, I worried about the data integrity because I'm not sure that pre and post hook perform in same db transaction.  
  > **username_1**: Depends on the requirement.  
  
  ---
  
  ### Answer by username_2 on 2018-10-10. Score: 0
  
  CiviCRM keeps log tables that document changes to core tables like `civicrm_membership`. They're all prefixed `log_`, so in this case you could look for the newest row in `log_civicrm_membership` for the relevant `contact_id` and/or `id` (`id` being the membership ID from the core table).
  
  That might contain enough data to help you distinguish between the two cases you describe.
  
  
  ---
  
  