How to change data field value based on a conditional field selection

I’m just starting out and trying to figure out how to use conditional functions in gravity forms.

I should do a date change based on a value of a select field
this is the function i have done so far but i can’t get it to work

//id form= 2
//field of select box= 8
//target date field= 13
//source date field= 7

add_filter( 'gform_pre_render', 'set_conditional_logic' );
add_filter( 'gform_pre_process', 'set_conditional_logic' );
function set_conditional_logic( $form ) {

   if ( $form['id'] !== 2 ) {
        return $form;
    }
	
 $duration = '';
 foreach ( $form['fields'] as &$field ) {
        if ( $field->id == 8 ) {
		 $duration = $field['value'];
	     }
    }
			
		if ( $duration == '12' ) 
		{	
        new GW_Populate_Date( array(
        'form_id' => 2,
        'target_field_id' => 13,
        'source_field_id' => 7,
        'modifier' => '+1 year'
		   ) );}
        else
		{
        new GW_Populate_Date( array(
        'form_id' => 2,
        'target_field_id' => 13,
        'source_field_id' => 7,
        'modifier' => '+2 year'
		   ) );
		   
		   }
		  
   return $form;
}

:pray:

Have you checked with Gravity Wiz for assistance with their snippet?

Also, my recommendation when doing anything custom with PHP code in Gravity Forms is to enable logging, and add your own custom logging statements to your code. Here’s how to do that:

Before those statements can do anything useful, you will need to enable logging: