How to check Sync to Mail Client for Specific User on List view

In Contacts module, I set specific user on Sync to Mail client field for all contacts.

It works and all contacts are sync to specific user's outlook.

In Contacts Record view field is Sync to Mail Client field checked according to specific user.
Main problem is in List View, Sync to Mail Client field is checked or unchecked according to current user(logged in user).

Record View - checkbox is checked

  

List View - checkbox is unchecked.

checkbox should checked according to specific user.

Parents Reply Children
  • Hi Chris,

    I have replaced current user to specific user in code.

    <?php

    require_once('modules/Contacts/Contact.php');

    class CustomContact extends Contact {

        // Specific user to add in contacts_user relationship
        public $specific_user = 'ffc9217a-9f1a-11e9-a804-34e6d7144ede';

        public function __construct() {
            parent::__construct();
            $this->specific_user_bean = BeanFactory::getBean('Users', $this->specific_user);
        }

        function fill_in_additional_detail_fields() {
            Person::fill_in_additional_detail_fields();
            if (empty($this->id))
                return;

            global $locale;

            $this->load_relationship('user_sync');

            if ($this->user_sync->_relationship->relationship_exists($this->specific_user_bean, $this)) {
                $this->sync_contact = true;
            } else {
                $this->sync_contact = false;
            }
            if (!empty($this->fetched_row)) {
                $this->fetched_row['sync_contact'] = $this->sync_contact;
            }

            /** concating this here because newly created Contacts do not have a
             * 'name' attribute constructed to pass onto related items, such as Tasks
             * Notes, etc.
             */

            $this->name = $locale->formatName($this);
        }

        function get_list_view_data($filter_fields = array()) {
            $temp_array = Person::get_list_view_data();

            if ($filter_fields && !empty($filter_fields['sync_contact'])) {
                $this->load_relationship('user_sync');
                $temp_array['SYNC_CONTACT'] = $this->user_sync->_relationship->relationship_exists($this->specific_user_bean, $this) ? 1 : 0;
            }
            $temp_array['EMAIL_AND_NAME1'] = "{$this->full_name} &lt;" . $temp_array['EMAIL1'] . "&gt;";
            return $temp_array;
        }

        /**
         *
         * @see Person::save()
         */

        public function save($check_notify = false) {
            if (!is_null($this->sync_contact)) {
                if (empty($this->fetched_row) || $this->fetched_row['sync_contact'] != $this->sync_contact) {
                    $this->load_relationship('user_sync');

                    if ($this->sync_contact) {
                        // They want to sync_contact
                        $this->user_sync->add($this->specific_user);
                    } else {
                        $this->user_sync->delete($this->id, $this->specific_user);
                    }
                }
            }
            return Person::save($check_notify);
        }

    }

    Can you advise what other approaches/solutions we can try to make it work?