Trigger Zappier hook when entry is deleted [RESOLVED]

Hi,

I have a form we have all of our clients fill to open a file at our Clinic. This form is then processed with a Workflow (gravity flow). In the process of opening the file, we have a Child form (gravity perks nested form) we use to book meetings with. Meetings are booked and sent to Google Calendar with the Zapier extension.

We are able to do all of the above but sometimes, we will need to delete meetings. Is there a way that, when deleting entries of the nested form, it could trigger a Zap (gravity flow) to delete the meeting in Google Calendar?

I was thinking of gform_delete_lead but I’m really beginner in all of this. I wouldn’t know what to put in the code…

Any help would be really appreciated.

Thanks

Michael

Hey Michael,

One approach that comes to mind which builds on the awesome setup you already have in place would be to:

  • Create a separate form that populates a dropdown with your list of nested meeting form entries (perhaps via Gravity Perks Populate Anything). Add a workflow to it, so that when that new entry is submitted you can:

  • Add a Zapier feed step to delete the Calendar entry

  • Use the Gravity Flow Form Connector and it’s delete an entry step type to specify the entry to delete based on that dropdown field. That keeps Calendar and nested entries in alignment.

  • If the Zapier feed needs more than just ID from the originating entry, the Form Connector’s Update Fields step type can let you map in exactly what is needed to administrative fields based on the selected entry ID.

  • If you also wanted to delete the new ‘request to delete a meeting’ entry, a second Delete Entry step could delete itself. Ensuring you have WP Cron properly processing, that will happen 15 mins after the workflow step.

Cheers,
Jamie

Hi Jamie,

Thank you very much for your help!

I’ll try to put this in place and will get back if I have any trouble with it.

I already have the Gravity Forms Connector. I couldn’t find how I could trigger anything upon the deletion of the entry itself. I saw that it’s possible to delete the entry of another form at a specific point in the workflow or delete the entry itself at a specific point. But this doesn’t seem to be exactly what I’m looking for.

What I need is that when I delete the any of the meetings in the nested form, it automatically deletes the Google Calendar event (through Zapier).

I will read all the stuff and get back to you.

Thanks again for your time, this is really appreciated

Michael

Hi Jamie,

I figured out a way that would be nice to do this without the need of adding another extension. Probably you can help me figure what’s wrong in my snippet of code?

Currently the nested form gets its fields updated everytime there’s a Submission of a Workflow step with the snippet below (provided by Gravity perks). I wanted to add the Restart Workflow so that if a check box is selected in the modified nested entry, the workflow will go through the process again and delete the Google Calendar event + delete the entry right after.

Here’s the snippet:

add_filter( 'gform_entry_post_save', 'gpnf_override_parent_merge_tags', 11, 2 );

add_action( 'gform_after_update_entry_26', function ( $form, $entry_id ) {
	$entry = GFAPI::get_entry( $entry_id );
	gpnf_override_parent_merge_tags( $entry, $form );
}, 11, 2 );

add_filter( 'gravityview-inline-edit/entry-updated', function( $return, $entry, $form_id ) {
	gpnf_override_parent_merge_tags( $entry, GFAPI::get_form( $form_id ) );
	return $return;
}, 10, 3 );

function gpnf_override_parent_merge_tags( $entry, $form ) {

	foreach ( $form['fields'] as $field ) {
		if ( $field->get_input_type() === 'form' ) {
			$child_form_id = $field->gpnfForm;
			$child_form    = GFAPI::get_form( $child_form_id );
			foreach ( $child_form['fields'] as $child_field ) {
				if ( $child_field->get_entry_inputs() ) {
					foreach ( $child_field->get_entry_inputs() as $input ) {
						preg_match( '/{Parent:(.+)}/i', rgar( $input, 'defaultValue' ), $match );
						if ( $match ) {
							$value           = rgar( $entry, $match[1] );
							$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
							$api = new Gravity_Flow_API( $child_form_id );
							foreach ( $child_entry_ids as $child_entry_id ) {
								GFAPI::update_entry_field( $child_entry_id, $input['id'], $value );
								$api->restart_workflow( $child_entry_id );
							}
						}
					}
				} else {
					preg_match( '/{Parent:(.+)}/i', $child_field->defaultValue, $match );
					if ( $match ) {
						$value           = rgar( $entry, $match[1] );
						$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
						$api = new Gravity_Flow_API( $child_form_id );
						foreach ( $child_entry_ids as $child_entry_id ) {
							GFAPI::update_entry_field( $child_entry_id, $child_field->id, $value );
							$api->restart_workflow( $child_entry_id );
						}
					}
				}
			}
		}
	}

	return $entry;
}

In this snippet the following lines are what we are looking to make work:

$api = new Gravity_Flow_API( $child_form_id );
$api->restart_workflow( $child_entry_id );

Do you see what’s wrong with this as it won’t fire the workflow over but will update all nested entries with the data.

Thanks in advance for your help!

Michael

Finally,

The code I gave triggered at every field that needed to be updated so I added a function… but it still doesn’t work properly… Sorry to ask again … but can you have a look at it?

/**
 * Gravity Perks // Nested Forms // Force {Parent} Merge Tag Replacement on Submission
 * http://gravitywiz.com/documentation/gravity-forms-nested-forms/
 *
 * Instruction Video: https://www.loom.com/share/5ff99681acb6462ea9268e1ff30cd220
 *
 * Override all {Parent} merge tags when the parent form is submitted or a parent entry is updated.
 */
add_filter( 'gform_entry_post_save', 'gpnf_override_parent_merge_tags', 11, 2 );
add_filter( 'gform_entry_post_save', 'msm_restart_workflow_post_save', 11, 2);

add_action( 'gform_after_update_entry_26', function ( $form, $entry_id ) {
	$entry = GFAPI::get_entry( $entry_id );
	gpnf_override_parent_merge_tags( $entry, $form );
	msm_restart_workflow_post_save( $entry, $form );
}, 11, 2 );

add_filter( 'gravityview-inline-edit/entry-updated', function( $return, $entry, $form_id ) {
	gpnf_override_parent_merge_tags( $entry, GFAPI::get_form( $form_id ) );
	return $return;
}, 10, 3 );

function msm_restart_workflow_post_save( $entry, $form ){
	foreach ( $form['fields'] as $field ) {
		if ( $field->get_input_type() === 'form' ) {
			$child_form_id = $field->gpnfForm;
			$child_form = GFAPI::get_form( $child_form_id );
			$api = new Gravity_Flow_API( $child_form_id );
			$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
			foreach ( $child_entry_ids as $child_entry_id ) {
				$childentry = GFAPI::get_entry($child_entry_id);
				$api->restart_workflow( $childentry );
			}
		}
	}
}

function gpnf_override_parent_merge_tags( $entry, $form ) {

	foreach ( $form['fields'] as $field ) {
		if ( $field->get_input_type() === 'form' ) {
			$child_form_id = $field->gpnfForm;
			$child_form    = GFAPI::get_form( $child_form_id );
			foreach ( $child_form['fields'] as $child_field ) {
				if ( $child_field->get_entry_inputs() ) {
					foreach ( $child_field->get_entry_inputs() as $input ) {
						preg_match( '/{Parent:(.+)}/i', rgar( $input, 'defaultValue' ), $match );
						if ( $match ) {
							$value           = rgar( $entry, $match[1] );
							$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
							foreach ( $child_entry_ids as $child_entry_id ) {
								GFAPI::update_entry_field( $child_entry_id, $input['id'], $value );
							}
						}
					}
				} else {
					preg_match( '/{Parent:(.+)}/i', $child_field->defaultValue, $match );
					if ( $match ) {
						$value           = rgar( $entry, $match[1] );
						$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
						foreach ( $child_entry_ids as $child_entry_id ) {
							GFAPI::update_entry_field( $child_entry_id, $child_field->id, $value );
						}
					}
				}
			}
		}
	}

	return $entry;
}

I was able to make this work by adding this snippet:

add_action( 'gform_after_update_entry_26', function ( $form, $entry_id ) {
	$entry = GFAPI::get_entry( $entry_id );
	msm_restart_workflow_post_save( $entry, $form );
}, 12, 2 );

function msm_restart_workflow_post_save( $entry, $form ){
	foreach ( $form['fields'] as $field ) {
		if ( $field->get_input_type() === 'form' ) {
			$child_form_id = $field->gpnfForm;
			$child_form = GFAPI::get_form( $child_form_id );
			$api = new Gravity_Flow_API( $child_form_id );
			$child_entry_ids = explode( ',', rgar( $entry, $field->id ) );
			foreach ( $child_entry_ids as $child_entry_id ) {
				$childentry = GFAPI::get_entry($child_entry_id);
				$api->restart_workflow( $childentry );
			}
		}
	}
}

This will restart workflow every time parent form is updated.

Thanks Jamie for your help, it’s really appreciated!

Michael

1 Like