Disciple.Tools Community D.T Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Disicple.Tools
    • Register
    • Login

    Workflow Action: Copy value from another field

    Scheduled Pinned Locked Moved Feature Requests
    2 Posts 1 Posters 411 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CairoCoderC Offline
      CairoCoder
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • CairoCoderC Offline
        CairoCoder
        last edited by CairoCoder

        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 );
        
        1 Reply Last reply Reply Quote 1

        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
        • First post
          Last post