Create an "Employer" Contact from a Custom Field.

Create an "Employer" Contact from a Custom Field.

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. 
  1. --Create Company Contacts
  2. --out of all the distinct company names
  3. --that are in the 'Employer Name' custom field.
  4. INSERT INTO __M_Contacts(
  5. Id,
  6. Final_Kind,
  7. Final_FullName
  8. ) SELECT DISTINCT
  9. V2.Final_Value,
  10. 'Company',
  11. V2.Final_Value
  12. FROM
  13. __M_CustomField_Definitions V1,
  14. __M_CustomField_Values V2,
  15. __M_Contacts V3
  16. WHERE 1=1
  17. AND V1.Final_Subject = 'Employer Name'
  18. AND V1.Id = V2.Final_CustomFieldDefinition_Id
  19. AND V2.Final_Parent_Type = '__M_Contacts'
  20. AND V2.Final_Parent_Id = V3.Id
  21. --Create Employer <=> Employee relationships
  22. --For all the values above
  23. INSERT INTO __M_Contacts_Related_Contacts(
  24. Id,
  25. Final_ParentContact_Id,
  26. Final_ParentContact_Kind,
  27. Final_ChildContact_Id,
  28. Final_ChildContact_Kind
  29. )
  30. SELECT DISTINCT
  31. V2.Id,
  32. V2.Final_Value,
  33. 'Employer',
  34. V2.Final_Parent_Id,
  35. 'Employee'
  36. FROM
  37. __M_CustomField_Definitions V1,
  38. __M_CustomField_Values V2,
  39. __M_Contacts V3
  40. WHERE 1=1
  41. AND V1.Final_Subject = 'Employer Name'
  42. AND V1.Id = V2.Final_CustomFieldDefinition_Id
  43. AND V2.Final_Parent_Type = '__M_Contacts'
  44. AND V2.Final_Parent_Id = V3.Id


    • Related Articles

    • Create a "Legacy Matter Number" Custom Field

      Some firms rely heavily on Matter Numbers to search for a specific matter. Sometimes when they migrate to a new system it can't replicate the automatic numbering system from their old system so they want to renumber all their matters to a new scheme ...
    • Custom Fields: Creating Custom Fields via Queries

      Sometimes you may need to create a new custom field to handle an unmapped column in a database. The queries below will help you do that. -- This is the ID we are giving our custom field definition. DECLARE @FieldId NVARCHAR(MAX) = 'ConNo --- CUSTOM' ...
    • Copy a Custom Field into a Core Field

      Some systems don't have certain core fields and clients often create a custom field that they use instead. The following script will let you copy values from a custom field named 'Opened' into __M_Matters.Final_Date_Opened . You can adjust this ...
    • Copy Calendar Entry Dates into Custom Field Values

      Some systems let you create custom fields that reference a Calendar Entry. When moving custom fields into a system that does not support this, an easy workaround would be to turn these custom fields into DateTime custom fields by copying in the start ...
    • Create Contact Categories from Matter Participants

      --The following script will create Contact Categories from the roles --that Contacts are linked to on Matters and then assign the contacts to those categories. GO INSERT INTO __M_Contacts_Categories ( Id, Final_Subject ) SELECT DISTINCT ...