Workflow Action: Copy value from another field
-
It would be useful in the workflow configurations to be able to copy a value from one field to another. My current use case is that there is a connections field for who is the "Digital Discipler" of a contact. When that is changed, we want to add those contact connections to the sub-assigned field. I could see this also being useful for other connections fields being copied to the sub-assigned field as well.
-
I was able to implement my own custom action that does this specifically for the sub-assigned field. The UI only allows the selection of a single field to perform an action on, so I used that as the source of where I want to copy a value from. This action will always copy it to the subassigned field but could be modified to alter other fields:
add_filter( 'dt_workflows_custom_actions', function ( $actions ) { $actions[] = (object) [ 'id' => 'mtm_copy_to_subassigned', 'name' => 'Copy Relation Field to Sub-assigned', 'displayed' => true // Within admin workflow builder view? ]; return $actions; }, 10, 1 ); add_action( 'mtm_copy_to_subassigned', function ( $post, $field, $value ) { if ( !empty( $post ) && $post['post_type'] === 'contacts' ) { $updated_post = []; $updated_post['subassigned']['values'] = []; if ( !empty( $post[$field] ) ) { foreach ( $post[$field] as $connection ) { $updated_post['subassigned']['values'][] = [ 'value' => $connection['ID'], ]; } } // Assuming we have updated fields, proceed with post update! if ( !empty( $updated_post['subassigned']['values'] ) ) { $updated_post['subassigned']['force_values'] = true; DT_Posts::update_post($post['post_type'], $post['ID'], $updated_post, false, false); } } }, 10, 3 );
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login