I want to bulk update the Employer field for the Individual contacts who have an active relationship of "employee of".
Even though we have many active employee relationships for individuals, the Employer field is blank.
CiviCRM Stack Exchange is a question and answer site for administrators and users of the CiviCRM Constituent Relationship Management software. It only takes a minute to sign up.Sign up to join this community
You can do this directly in the database by running the following update query:
UPDATE civicrm_contact, (civicrm_relationship r LEFT JOIN civicrm_contact c ON c.id = r.contact_id_a) LEFT JOIN civicrm_contact c1 ON c1.id = r.contact_id_b SET c.employer_id = r.contact_id_b, c.organization_name = c1.organization_name WHERE r.relationship_type_id = 5 AND c.contact_type = 'individual' AND c.employer_id IS NULL AND r.is_active = 1
This will update the employer field for all individual contacts who have an active employee relationship and do not have an employer already set.