1

Instead of updating the Participant,its creating new participant.I need to change participant status from registered to attended and vice versa.

civicrm_initialize();
  $result = civicrm_api3('Participant', 'create', [
  'id' => $entity_id,
  'contact_id' => $context['civicrm_participant']->contact_id,
  'event_id'   => $context['civicrm_participant']->event_id,
  'status_id' => "Registered",
]);

I am executing the above code in the hook_action_info() drupal 7 using views bulk operations & custom entity module

function custom_changes_action_info() {
  return array(
     'custom_changes_actions_participant_status_attended_action' => array(
         'type' => 'civicrm_participant',
         'label' => t('Change Participant Status to Attended'),
         'configurable' => FALSE,
         'behavior' => array('changes_property'),
         'triggers' => array('any'),
     ),
      'custom_changes_actions_participant_status_registered_action' => array(
         'type' => 'civicrm_participant',
         'label' => t('Change Participant Status to Registered'),
         'configurable' => FALSE,
         'behavior' => array('changes_property'),
         'triggers' => array('any'),
     ),
  ); 
}

function custom_changes_actions_participant_status_attended_action($entity, $context = array()) {


  $entity_id = $entity->{$info['entity keys']['id']};

  civicrm_initialize();
 $result = civicrm_api3('Participant', 'create', [
  'id' => $entity_id,
  'contact_id' => $context['civicrm_participant']->contact_id,
  'event_id'   => $context['civicrm_participant']->event_id,
  'status_id' => "Attended",
]);
  //drupal_set_message($entity_id. 'entity_id');
 // $base_url = str_replace('_', '-', $context['entity_type']); // civicrm-participant
  //civicrm_entity_drupal_goto($base_url . '/' . $entity_id . '/edit');
}
4

Since you are passing $entity_id to id in participant params without checking it to be not empty. If $entity_id is empty then new participant will be created else it will be updated. Make sure your id is set before calling to participant api if you want to update the participant

Cheers

Pradeep

  • Hi @Pradeep , even when it has values it does not work. debugging it further we are using a batch operation, does that have any reason for the api to not work as when I add die() inside function custom_changes_actions_participant_status_attended_action() it changes the status, otherwise it does not – harshal Jan 24 at 15:05
  • That sounds different to your original question ... not changing status vs creating new participants. Can you clarify in the question what you are seeing? – Aidan Jan 25 at 9:19

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.