In some systems, contacts do not have an Employer relation and only have a text field that represents the employer. This script will help when moving firms into platforms that allow an actual contact to be specified for the employer.
- --Create Company Contacts
- --out of all the distinct company names
- --that are in the 'Employer Name' custom field.
- INSERT INTO __M_Contacts(
- Id,
- Final_Kind,
- Final_FullName
- )
SELECT DISTINCT
- V2.Final_Value,
- 'Company',
- V2.Final_Value
- FROM
- __M_CustomField_Definitions V1,
- __M_CustomField_Values V2,
- __M_Contacts V3
- WHERE 1=1
- AND V1.Final_Subject = 'Employer Name'
- AND V1.Id = V2.Final_CustomFieldDefinition_Id
- AND V2.Final_Parent_Type = '__M_Contacts'
- AND V2.Final_Parent_Id = V3.Id
-
--Create Employer <=> Employee relationships
- --For all the values above
- INSERT INTO __M_Contacts_Related_Contacts(
- Id,
- Final_ParentContact_Id,
- Final_ParentContact_Kind,
- Final_ChildContact_Id,
- Final_ChildContact_Kind
- )
- SELECT DISTINCT
- V2.Id,
- V2.Final_Value,
- 'Employer',
- V2.Final_Parent_Id,
- 'Employee'
- FROM
- __M_CustomField_Definitions V1,
- __M_CustomField_Values V2,
- __M_Contacts V3
- WHERE 1=1
- AND V1.Final_Subject = 'Employer Name'
- AND V1.Id = V2.Final_CustomFieldDefinition_Id
- AND V2.Final_Parent_Type = '__M_Contacts'
- AND V2.Final_Parent_Id = V3.Id