gravityflowformconnector_update_entry_id

The gravityflowformconnector_update_entry_id filter allows the target entry ID to be modified.

Parameters

Parameter Type Definition
$target_entry_id Integer The target entry id.
$target_form_id Integer The target form id.
$entry Array The current entry object.
$form Array The current form object.
$step Array The current step object.

Examples

Example 1 - Custom search for the target entry ID based on the value of field ID 4.

add_filter( 'gravityflowformconnector_update_entry_id', 'sh_gravityflowformconnector_update_entry_id', 10, 5);
  function sh_gravityflowformconnector_update_entry_id( $target_entry_id, $target_form_id, $entry, $form, $step ) {
      // Custom search for the target entry ID based on the value of field ID 4.
      $search_criteria['status'] = 'active';
      $search_criteria['field_filters'][] = array( 'key' => '2', 'value' => $entry['4'] );
      $entries = GFAPI::get_entries( $target_form_id, $search_criteria );
      // Return the ID of the first entry in the results.
      return $entries[0]['id'];
  }

Example 2 - Custom search for the target entry ID across multiple form fields' for multiple steps.

Similar to Example 1 in it's use of the GFAPI::get_entries function, it compares the entry field value against multiple form fields based on the particular step. 

add_filter( 'gravityflowformconnector_update_entry_id', 'match_first_matters_id', 10, 5 );
function match_first_matters_id( $target_entry_id, $target_form_id, $entry, $form, $step ) {
 
	if ( false == $step ) {
        return false;
    }

	//Ensure this filter only applies for the desired form ID.
	if ( $form['id'] != '15' ) {
        return $target_entry_id;
    }

    $step_id = $step->get_id();

    //Update the list of step IDs you want this to execute against
    if ( false == in_array( $step_id, array( '65', '66', '68', '69', '70', '71' ) ) ) {
        return $target_entry_id;
    }

	$original_matter_name = $entry['1'];

	switch ($step_id):
		//Adjust step ID (case), search_form_id and the field in it to match your use case
		case 65:
		case 66:
			$search_form_id = '17';
			$search_criteria['field_filters'][] = array( 'key' => '3', 'value' => $original_matter_name );
		break;

		//Adjust step ID (case), search_form_id and the field in it to match your use case
		case 68:
		case 69:
			$search_form_id = '18';
			$search_criteria['field_filters'][] = array( 'key' => '2', 'value' => $original_matter_name );
			break;
	endswitch;
	
	$paging         = array( 'offset' => 0, 'page_size' => 1 );
	$total_count    = 0;
	$matched_entries = GFAPI::get_entries( $search_form_id, $search_criteria, array(), $paging, $total_count );

	if( ! empty( $matched_entries ) ) {
		foreach( $matched_entries as $matched_entry ) {
			return $matched_entry['id'];
		}
	}

	return $target_entry_id;
}

When combined with example 5 from the gravityflow_step_is_condition_met filter docs, you can use two Form Connector Update an Entry steps to ensure all entries which match the expected field value get changed.  If using this approach, you would setup two Update an Entry steps with the same settings as shown in this screenshot. The first would have it's Next Step setting point to 'Next step in List' while the second would point back to the first. In that way, as soon as the series of steps both fail their gravityflow_step_is_condition_met filter, you know that all entries have been updated.

Placement

This code should be placed in the functions.php file of your active theme or in a custom functions plugin.